Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import threading
import time
import eventlet
import eventlet.corolocal
# NOTE(rpodolyaka): threading is patched here
# NOTE(rpodolyaka): meant to be 'thread local storage' for green threads
# currently we use like this
#local = eventlet.corolocal.local
# but in fact it must be used like this
local = eventlet.corolocal.local()
def f(): = eventlet.corolocal.get_ident() # is unique for each green thread
while True:
print 'Thread %d -> local storage value = %d' % (eventlet.corolocal.get_ident(),
time.sleep(2) # yield
for i in xrange(3):
t = threading.Thread(target=f) # these are green threads
while True:
print '-------------'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment