Created
January 29, 2014 08:53
-
-
Save amotoki/8684114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import time | |
import eventlet | |
import eventlet.corolocal | |
# NOTE(rpodolyaka): threading is patched here | |
eventlet.monkey_patch() | |
# 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(): | |
local.id = eventlet.corolocal.get_ident() # is unique for each green thread | |
while True: | |
print 'Thread %d -> local storage value = %d' % (eventlet.corolocal.get_ident(), local.id) | |
time.sleep(2) # yield | |
for i in xrange(3): | |
t = threading.Thread(target=f) # these are green threads | |
t.start() | |
while True: | |
#time.sleep(0) | |
print '-------------' | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment