Commit eac324b9 authored by Martin v. Löwis's avatar Martin v. Löwis

Patch #957240: Add count parameter to asyncore.loop.

parent 3e501dcf
...@@ -44,20 +44,20 @@ channel (including any that have been added to the map during asynchronous ...@@ -44,20 +44,20 @@ channel (including any that have been added to the map during asynchronous
service) is closed. service) is closed.
\begin{funcdesc}{loop}{\optional{timeout\optional{, use_poll\optional{, \begin{funcdesc}{loop}{\optional{timeout\optional{, use_poll\optional{,
map}}}} map\optional{,count}}}}}
Enter a polling loop that only terminates after all open channels Enter a polling loop that terminates after count passes or all open
have been closed. All arguments are optional. The \var{timeout} channels have been closed. All arguments are optional. The \var(count)
argument sets the timeout parameter for the appropriate parameter defaults to infinity, resulting in the loop terminating only
\function{select()} or \function{poll()} call, measured in seconds; when all channels have been closed. The \var{timeout} argument sets the
the default is 30 seconds. The \var{use_poll} parameter, if true, timeout parameter for the appropriate \function{select()} or
indicates that \function{poll()} should be used in preference to \function{poll()} call, measured in seconds; the default is 30 seconds.
\function{select()} (the default is \code{False}). The \var{map} parameter The \var{use_poll} parameter, if true, indicates that \function{poll()}
is a dictionary whose items are the channels to watch. As channels should be used in preference to \function{select()} (the default is
are closed they are deleted from their map. If \var{map} is \code{False}). The \var{map} parameter is a dictionary whose items are
omitted, a global map is used (this map is updated by the default the channels to watch. As channels are closed they are deleted from their
class \method{__init__()} map. If \var{map} is omitted, a global map is used (this map is updated
-- make sure you extend, rather than override, \method{__init__()} by the default class \method{__init__()} -- make sure you extend, rather
if you want to retain this behavior). than override, \method{__init__()} if you want to retain this behavior).
Channels (instances of \class{asyncore.dispatcher}, \class{asynchat.async_chat} Channels (instances of \class{asyncore.dispatcher}, \class{asynchat.async_chat}
and subclasses thereof) can freely be mixed in the map. and subclasses thereof) can freely be mixed in the map.
......
...@@ -157,7 +157,7 @@ def poll2(timeout=0.0, map=None): ...@@ -157,7 +157,7 @@ def poll2(timeout=0.0, map=None):
poll3 = poll2 # Alias for backward compatibility poll3 = poll2 # Alias for backward compatibility
def loop(timeout=30.0, use_poll=False, map=None): def loop(timeout=30.0, use_poll=False, map=None, count=1e309):
if map is None: if map is None:
map = socket_map map = socket_map
...@@ -166,8 +166,9 @@ def loop(timeout=30.0, use_poll=False, map=None): ...@@ -166,8 +166,9 @@ def loop(timeout=30.0, use_poll=False, map=None):
else: else:
poll_fun = poll poll_fun = poll
while map: while map and count >= 0:
poll_fun(timeout, map) poll_fun(timeout, map)
count = count - 1
class dispatcher: class dispatcher:
......
...@@ -319,6 +319,8 @@ Extension modules ...@@ -319,6 +319,8 @@ Extension modules
Library Library
------- -------
- asyncore.loop now has repeat count parameter that defaults to infinity.
- The distutils sdist command now ignores all .svn directories, in - The distutils sdist command now ignores all .svn directories, in
addition to CVS and RCS directories. .svn directories hold addition to CVS and RCS directories. .svn directories hold
administrative files for the Subversion source control system. administrative files for the Subversion source control system.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment