green: select: ensure that hub can .wait() at least once before timeout
https://github.com/eventlet/eventlet/pull/25
This commit is contained in:

committed by
Sergey Shepelev

parent
e34c88d558
commit
2adaeb6159
@@ -30,7 +30,7 @@ def select(read_list, write_list, error_list, timeout=None):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise TypeError("Expected number for timeout")
|
raise TypeError("Expected number for timeout")
|
||||||
hub = get_hub()
|
hub = get_hub()
|
||||||
t = None
|
timers = []
|
||||||
current = getcurrent()
|
current = getcurrent()
|
||||||
assert hub.greenlet is not current, 'do not call blocking functions from the mainloop'
|
assert hub.greenlet is not current, 'do not call blocking functions from the mainloop'
|
||||||
ds = {}
|
ds = {}
|
||||||
@@ -55,11 +55,20 @@ def select(read_list, write_list, error_list, timeout=None):
|
|||||||
original = ds[get_fileno(d)]['error']
|
original = ds[get_fileno(d)]['error']
|
||||||
current.switch(([], [], [original]))
|
current.switch(([], [], [original]))
|
||||||
|
|
||||||
def on_timeout():
|
def on_timeout2():
|
||||||
current.switch(([], [], []))
|
current.switch(([], [], []))
|
||||||
|
|
||||||
|
def on_timeout():
|
||||||
|
# ensure that BaseHub.run() has a chance to call self.wait()
|
||||||
|
# at least once before timed out. otherwise the following code
|
||||||
|
# can time out erroneously.
|
||||||
|
#
|
||||||
|
# s1, s2 = socket.socketpair()
|
||||||
|
# print select.select([], [s1], [], 0)
|
||||||
|
timers.append(hub.schedule_call_global(0, on_timeout2))
|
||||||
|
|
||||||
if timeout is not None:
|
if timeout is not None:
|
||||||
t = hub.schedule_call_global(timeout, on_timeout)
|
timers.append(hub.schedule_call_global(timeout, on_timeout))
|
||||||
try:
|
try:
|
||||||
for k, v in ds.iteritems():
|
for k, v in ds.iteritems():
|
||||||
if v.get('read'):
|
if v.get('read'):
|
||||||
@@ -72,6 +81,5 @@ def select(read_list, write_list, error_list, timeout=None):
|
|||||||
for l in listeners:
|
for l in listeners:
|
||||||
hub.remove(l)
|
hub.remove(l)
|
||||||
finally:
|
finally:
|
||||||
if t is not None:
|
for t in timers:
|
||||||
t.cancel()
|
t.cancel()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user