rackspace/python-cloudfiles — Issue #65: gevent issues
Author: aljosa
Created: 2012-03-02 00:34:58+00:00
State: open

code works w/o gevent when run synchronized but when i try to use gevent to make it do parallel execution it fails.

output:

'NoneType' object has no attribute 'makefile'
^CTraceback (most recent call last):
File "gevent_test.py", line 32, in
gevent.joinall(jobs)
File "/home/aljosa/Projects/lsn/env/local/lib/python2.7/site-packages/gevent/greenlet.py", line 502, in joinall
queue.get()
File "/home/aljosa/Projects/lsn/env/local/lib/python2.7/site-packages/gevent/queue.py", line 190, in get
return waiter.get()
File "/home/aljosa/Projects/lsn/env/local/lib/python2.7/site-packages/gevent/hub.py", line 321, in get
return get_hub().switch()
File "/home/aljosa/Projects/lsn/env/local/lib/python2.7/site-packages/gevent/hub.py", line 164, in switch
return greenlet.switch(self)
KeyboardInterrupt
Exception KeyError: KeyError(43063608,) in ignored

code:

from os import walk
from os.path import abspath, join, dirname
import cloudfiles
import gevent
from gevent import monkey

monkey.patch_all()

conn = cloudfiles.get_connection("user", "password")
c = conn.get_container('static')
L = ['static/flags/cn.gif', 'static/flags/lc.gif', 'static/flags/ly.gif', 'static/flags/cu.gif', 'static/flags/an.gif']

def upload(file):
while True:
try:
obj = c.create_object(file)
obj.load_from_filename(file)
obj.headers["Access-Control-Allow-Origin"] = "*"
obj.sync_metadata()
break
except Exception, ex:
print ex

jobs = [gevent.spawn(upload, f) for f in L]
gevent.joinall(jobs)