From 01c8f3b66d5c40e3d3fdda6f884bc76ea9193380 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Mon, 22 Jan 2018 22:37:29 +0100 Subject: [PATCH] Fix asyncore CPU usage on no connection - if there are no connections, asyncore would hog CPU - thanks to an anonymous contributor --- src/network/asyncore_pollchoose.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/network/asyncore_pollchoose.py b/src/network/asyncore_pollchoose.py index 5717ff78..de8ededc 100644 --- a/src/network/asyncore_pollchoose.py +++ b/src/network/asyncore_pollchoose.py @@ -52,6 +52,7 @@ import select import socket import sys import time +from threading import current_thread import warnings import os @@ -246,6 +247,8 @@ def select_poller(timeout=0.0, map=None): if obj is None: continue _exception(obj) + else: + current_thread().stop.wait(timeout) def poll_poller(timeout=0.0, map=None): """A poller which uses poll(), available on most UNIXen.""" @@ -294,6 +297,8 @@ def poll_poller(timeout=0.0, map=None): if obj is None: continue readwrite(obj, flags) + else: + current_thread().stop.wait(timeout) # Aliases for backward compatibility poll = select_poller @@ -349,6 +354,8 @@ def epoll_poller(timeout=0.0, map=None): if obj is None: continue readwrite(obj, flags) + else: + current_thread().stop.wait(timeout) def kqueue_poller(timeout=0.0, map=None): """A poller which uses kqueue(), BSD specific.""" @@ -383,6 +390,8 @@ def kqueue_poller(timeout=0.0, map=None): if event.filter == select.KQ_FILTER_WRITE: write(obj) kqueue.close() + else: + current_thread().stop.wait(timeout) def loop(timeout=30.0, use_poll=False, map=None, count=None,