EuroPython, Florence, 2011-06-20
Why emulate coroutine implementations with each other?
These numbers useless as metrics, thus they are not fair.
These numbers useless as metrics, thus they are not fair.
Coroutines are also useful for just a dozen connections:
import gc import sys from greenlet import greenlet def F(other_ref, x): greenlet.getcurrent().parent.switch(42) x = [] xr = sys.getrefcount(x) g = [greenlet(F), greenlet(F)] assert 42 == g[0].switch(g[1], x) assert 42 == g[1].switch(g[0], x) # Comment this line to fix. del g[:] gc.collect() print sys.getrefcount(x) - xr #: 4, greenlets still not deleted.
import gc import sys import stackless def F(other_ref, x): stackless.schedule_remove() x = [] xr = sys.getrefcount(x) g = [stackless.tasklet(F), stackless.tasklet(F)] g[0](g[1], x) g[1](g[0], x) print sys.getrefcount(x) - xr #: 2 g[0].run() g[1].run() del g[:] print sys.getrefcount(x) - xr #: 1, tasklets not deleted yet. gc.collect() print sys.getrefcount(x) - xr #: 0, tasklets deleted.
Pedantic:
Tricky:
?