From 607af36ad3ac9716d8820572538e4071babe1a5a Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 20 Jan 2015 14:08:30 +0100 Subject: [PATCH] workaround for the "Bad file descriptor" issue on Python 2.7, gh-161 : asyncore.loop() using poll by the way, prevents to write "'build/bdist.linux-x86_64' does not exist -- can't clean it" into stderr; --- fail2ban/server/asyncserver.py | 7 +++++-- fail2ban/tests/misctestcase.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fail2ban/server/asyncserver.py b/fail2ban/server/asyncserver.py index a54d41a1d..c99cdffe0 100644 --- a/fail2ban/server/asyncserver.py +++ b/fail2ban/server/asyncserver.py @@ -149,8 +149,11 @@ class AsyncServer(asyncore.dispatcher): self.__init = True # TODO Add try..catch # There's a bug report for Python 2.6/3.0 that use_poll=True yields some 2.5 incompatibilities: - logSys.debug("Detected Python 2.6 or greater. asyncore.loop() not using poll") - asyncore.loop(use_poll=False) # fixes the "Unexpected communication problem" issue on Python 2.6 and 3.0 + if sys.version_info >= (2, 7) and sys.version_info < (2, 8): # if python 2.7 ... + logSys.debug("Detected Python 2.7. asyncore.loop() using poll") + asyncore.loop(use_poll=True) # workaround for the "Bad file descriptor" issue on Python 2.7, gh-161 + else: + asyncore.loop(use_poll=False) # fixes the "Unexpected communication problem" issue on Python 2.6 and 3.0 ## # Stops the communication server. diff --git a/fail2ban/tests/misctestcase.py b/fail2ban/tests/misctestcase.py index 2f69aef0e..a682b63f1 100644 --- a/fail2ban/tests/misctestcase.py +++ b/fail2ban/tests/misctestcase.py @@ -113,7 +113,7 @@ class SetupTest(unittest.TestCase): # clean up shutil.rmtree(tmp) # remove build directory - os.system("%s %s clean --all >/dev/null" + os.system("%s %s clean --all >/dev/null 2>&1" % (sys.executable, self.setup)) class TestsUtilsTest(unittest.TestCase):