Skip to content

Commit

Permalink
Fixed collections.Callable Python 3.9 issue (#443)
Browse files Browse the repository at this point in the history
* Fixed collections.Callable Python 3.9 issue

* Fixing lint issue

* Made it possible to remove the target info tags

* Added missing dependancy
  • Loading branch information
johann8384 authored Oct 20, 2020
1 parent 228d593 commit e86209c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tcollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import base64
from logging.handlers import RotatingFileHandler
from optparse import OptionParser

import collections

PY3 = sys.version_info[0] > 2
Expand All @@ -46,10 +47,12 @@
from urllib.request import Request, urlopen # pylint: disable=maybe-no-member,no-name-in-module,import-error
from urllib.error import HTTPError, URLError # pylint: disable=maybe-no-member,no-name-in-module,import-error
from http.server import HTTPServer, BaseHTTPRequestHandler # pylint: disable=maybe-no-member,no-name-in-module,import-error
from collections.abc import Callable # pylint: disable=maybe-no-member,no-name-in-module,import-error
else:
from Queue import Queue, Empty, Full # pylint: disable=maybe-no-member,no-name-in-module,import-error
from urllib2 import Request, urlopen, HTTPError, URLError # pylint: disable=maybe-no-member,no-name-in-module,import-error
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler # pylint: disable=maybe-no-member,no-name-in-module,import-error
from collections import Callable # pylint: disable=maybe-no-member,no-name-in-module,import-error

# global variables.
COLLECTORS = {}
Expand Down Expand Up @@ -156,6 +159,9 @@ def read(self):
except IOError as exc:
if exc.errno != errno.EAGAIN:
raise
except TypeError as exc:
# Sometimes the underlying buffer.read() returns None
LOG.debug("Recieved None while trying to read stderr")
except:
LOG.exception('uncaught exception in stderr read')

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

0 comments on commit e86209c

Please sign in to comment.