From: Charles-François Natali Date: Sun, 8 Sep 2013 09:30:53 +0000 (+0200) Subject: Issue #18934: Use poll/select-based selectors for multiprocessing.Connection, X-Git-Tag: v3.4.0a3~27^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45e255167eb8cc34c85439dbdc8074a9b25bec2d;p=python Issue #18934: Use poll/select-based selectors for multiprocessing.Connection, to avoid one extra FD per Connection. --- diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index 59fb6640d5..27fda9f22c 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -878,13 +878,21 @@ else: import selectors + # poll/select have the advantage of not requiring any extra file + # descriptor, contrarily to epoll/kqueue (also, they require a single + # syscall). + if hasattr(selectors, 'PollSelector'): + _WaitSelector = selectors.PollSelector + else: + _WaitSelector = selectors.SelectSelector + def wait(object_list, timeout=None): ''' Wait till an object in object_list is ready/readable. Returns list of those objects in object_list which are ready/readable. ''' - with selectors.DefaultSelector() as selector: + with _WaitSelector() as selector: for obj in object_list: selector.register(obj, selectors.EVENT_READ)