I don't think it's safe to use map.iteritems() in the various poll

routines.  I got some errors "dictionary changed size during
iteration" when running ZEO tests on machine while doing heavy
forground work in another window, and thinking about it, I believe
that it should be okay if readable() or writable() modifies the map.

I also finally made all the spacing conform to the Python style guide:
no space between a function/method name and the following left
parenthesis (fixed lots of occurrences), spaces around assignment
operators (fixed a few, always of the form "map=..."), and a blank
line between the class statement and the first method definition (a
few).
This commit is contained in:
Guido van Rossum 2002-09-12 04:57:29 +00:00
parent 78170048f9
commit d560ace3a7

View file

@ -95,7 +95,7 @@ def poll (timeout=0.0, map=None):
map = socket_map map = socket_map
if map: if map:
r = []; w = []; e = [] r = []; w = []; e = []
for fd, obj in map.iteritems(): for fd, obj in map.items():
if obj.readable(): if obj.readable():
r.append(fd) r.append(fd)
if obj.writable(): if obj.writable():
@ -127,7 +127,7 @@ def poll2 (timeout=0.0, map=None):
timeout = int(timeout*1000) timeout = int(timeout*1000)
if map: if map:
l = [] l = []
for fd, obj in map.iteritems(): for fd, obj in map.items():
flags = 0 flags = 0
if obj.readable(): if obj.readable():
flags = poll.POLLIN flags = poll.POLLIN
@ -151,7 +151,7 @@ def poll3 (timeout=0.0, map=None):
timeout = int(timeout*1000) timeout = int(timeout*1000)
pollster = select.poll() pollster = select.poll()
if map: if map:
for fd, obj in map.iteritems(): for fd, obj in map.items():
flags = 0 flags = 0
if obj.readable(): if obj.readable():
flags = select.POLLIN flags = select.POLLIN
@ -187,6 +187,7 @@ def loop (timeout=30.0, use_poll=0, map=None):
poll_fun(timeout, map) poll_fun(timeout, map)
class dispatcher: class dispatcher:
debug = 0 debug = 0
connected = 0 connected = 0
accepting = 0 accepting = 0
@ -433,6 +434,7 @@ class dispatcher:
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
class dispatcher_with_send(dispatcher): class dispatcher_with_send(dispatcher):
def __init__(self, sock=None): def __init__(self, sock=None):
dispatcher.__init__(self, sock) dispatcher.__init__(self, sock)
self.out_buffer = '' self.out_buffer = ''
@ -504,6 +506,7 @@ if os.name == 'posix':
class file_wrapper: class file_wrapper:
# here we override just enough to make a file # here we override just enough to make a file
# look like a socket for the purposes of asyncore. # look like a socket for the purposes of asyncore.
def __init__(self, fd): def __init__(self, fd):
self.fd = fd self.fd = fd
@ -523,6 +526,7 @@ if os.name == 'posix':
return self.fd return self.fd
class file_dispatcher(dispatcher): class file_dispatcher(dispatcher):
def __init__(self, fd): def __init__(self, fd):
dispatcher.__init__(self) dispatcher.__init__(self)
self.connected = 1 self.connected = 1