Skip to content

Commit e86209c

Browse files
authored
Fixed collections.Callable Python 3.9 issue (#443)
* Fixed collections.Callable Python 3.9 issue * Fixing lint issue * Made it possible to remove the target info tags * Added missing dependancy
1 parent 228d593 commit e86209c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tcollector.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import base64
3838
from logging.handlers import RotatingFileHandler
3939
from optparse import OptionParser
40+
4041
import collections
4142

4243
PY3 = sys.version_info[0] > 2
@@ -46,10 +47,12 @@
4647
from urllib.request import Request, urlopen # pylint: disable=maybe-no-member,no-name-in-module,import-error
4748
from urllib.error import HTTPError, URLError # pylint: disable=maybe-no-member,no-name-in-module,import-error
4849
from http.server import HTTPServer, BaseHTTPRequestHandler # pylint: disable=maybe-no-member,no-name-in-module,import-error
50+
from collections.abc import Callable # pylint: disable=maybe-no-member,no-name-in-module,import-error
4951
else:
5052
from Queue import Queue, Empty, Full # pylint: disable=maybe-no-member,no-name-in-module,import-error
5153
from urllib2 import Request, urlopen, HTTPError, URLError # pylint: disable=maybe-no-member,no-name-in-module,import-error
5254
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler # pylint: disable=maybe-no-member,no-name-in-module,import-error
55+
from collections import Callable # pylint: disable=maybe-no-member,no-name-in-module,import-error
5356

5457
# global variables.
5558
COLLECTORS = {}
@@ -156,6 +159,9 @@ def read(self):
156159
except IOError as exc:
157160
if exc.errno != errno.EAGAIN:
158161
raise
162+
except TypeError as exc:
163+
# Sometimes the underlying buffer.read() returns None
164+
LOG.debug("Recieved None while trying to read stderr")
159165
except:
160166
LOG.exception('uncaught exception in stderr read')
161167

@@ -174,6 +180,9 @@ def read(self):
174180
# sometimes the process goes away in another thread and we don't
175181
# have it anymore, so log an error and bail
176182
LOG.exception('caught exception, collector process went away while reading stdout')
183+
except TypeError as exc:
184+
# Sometimes the underlying buffer.read() returns None
185+
LOG.debug("Recieved None while trying to read stdout")
177186
except:
178187
LOG.exception('uncaught exception in stdout read')
179188
return
@@ -1306,7 +1315,7 @@ def load_config_module(name, options, tags):
13061315
else:
13071316
module = reload(name) # pylint: disable=undefined-variable
13081317
onload = module.__dict__.get('onload')
1309-
if isinstance(onload, collections.Callable):
1318+
if isinstance(onload, Callable):
13101319
try:
13111320
onload(options, tags)
13121321
except:

0 commit comments

Comments
 (0)