Added a test to the parent assignment in hub.switch because the constant ValueErrors were confusing me. Yields a slight performance improvement, the benchmark shows.

This commit is contained in:
Ryan Williams
2010-02-13 12:19:33 -08:00
parent 5b3759f791
commit 01b0886804
2 changed files with 21 additions and 5 deletions

View File

@@ -3,6 +3,23 @@
import eventlet
import benchmarks
def cleanup():
eventlet.sleep(0.2)
iters = 10000
best = benchmarks.measure_best(5, iters,
'pass',
cleanup,
eventlet.sleep)
print "eventlet.sleep (main)", best[eventlet.sleep]
gt = eventlet.spawn(benchmarks.measure_best,5, iters,
'pass',
cleanup,
eventlet.sleep)
best = gt.wait()
print "eventlet.sleep (gt)", best[eventlet.sleep]
def dummy(i=None):
return i
@@ -15,10 +32,7 @@ def run_spawn_n():
def run_spawn_n_kw():
eventlet.spawn_n(dummy, i=1)
def cleanup():
eventlet.sleep(0.2)
iters = 10000
best = benchmarks.measure_best(5, iters,
'pass',
cleanup,

View File

@@ -112,9 +112,11 @@ class BaseHub(object):
if self.greenlet.dead:
self.greenlet = greenlet.greenlet(self.run)
try:
greenlet.getcurrent().parent = self.greenlet
current = greenlet.getcurrent()
if self.greenlet.parent is not current:
current.parent = self.greenlet
except ValueError:
pass
pass # gets raised if there is a greenlet parent cycle
return self.greenlet.switch()
def squelch_exception(self, fileno, exc_info):