Fix asyncore CPU usage on no connection

- if there are no connections, asyncore would hog CPU
- thanks to an anonymous contributor
This commit is contained in:
Peter Šurda 2018-01-22 22:37:29 +01:00
parent ba91d21261
commit 01c8f3b66d
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -52,6 +52,7 @@ import select
import socket import socket
import sys import sys
import time import time
from threading import current_thread
import warnings import warnings
import os import os
@ -246,6 +247,8 @@ def select_poller(timeout=0.0, map=None):
if obj is None: if obj is None:
continue continue
_exception(obj) _exception(obj)
else:
current_thread().stop.wait(timeout)
def poll_poller(timeout=0.0, map=None): def poll_poller(timeout=0.0, map=None):
"""A poller which uses poll(), available on most UNIXen.""" """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: if obj is None:
continue continue
readwrite(obj, flags) readwrite(obj, flags)
else:
current_thread().stop.wait(timeout)
# Aliases for backward compatibility # Aliases for backward compatibility
poll = select_poller poll = select_poller
@ -349,6 +354,8 @@ def epoll_poller(timeout=0.0, map=None):
if obj is None: if obj is None:
continue continue
readwrite(obj, flags) readwrite(obj, flags)
else:
current_thread().stop.wait(timeout)
def kqueue_poller(timeout=0.0, map=None): def kqueue_poller(timeout=0.0, map=None):
"""A poller which uses kqueue(), BSD specific.""" """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: if event.filter == select.KQ_FILTER_WRITE:
write(obj) write(obj)
kqueue.close() kqueue.close()
else:
current_thread().stop.wait(timeout)
def loop(timeout=30.0, use_poll=False, map=None, count=None, def loop(timeout=30.0, use_poll=False, map=None, count=None,