Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pickle, cPicke 都无法序列化gevent.event.Event() #1

Open
salmonx opened this issue May 27, 2016 · 2 comments
Open

pickle, cPicke 都无法序列化gevent.event.Event() #1

salmonx opened this issue May 27, 2016 · 2 comments

Comments

@salmonx
Copy link

salmonx commented May 27, 2016

TypeError: cannot serialize 'Hub' object

from gevent import event
e = event.Event()
type(e)
<class 'gevent.event.Event'>

import pickle
pickle.dumps(e)
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/pickle.py", line 1380, in dumps
Pickler(file, protocol).dump(obj)
File "/usr/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, _rv)
File "/usr/lib/python2.7/pickle.py", line 425, in save_reduce
save(state)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "/usr/lib/python2.7/pickle.py", line 669, in _batch_setitems
save(v)
File "/usr/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/usr/lib/python2.7/copy_reg.py", line 84, in reduce_ex
dict = getstate()
TypeError: cannot serialize 'Hub' object
*
>>> import cPickle as pickle
pickle.dumps(e)**
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/copy_reg.py", line 84, in _reduce_ex
dict = getstate()
TypeError: cannot serialize 'Hub' object

@salmonx
Copy link
Author

salmonx commented May 27, 2016

Now, I have changed a little to fix it.

Make the event variable "e" global variable, and in redis we do need to store the event.

cache=Cache()
evt = event.Event()

def handle_response(data):
e=cache.get(qname+"e")
cache.remove(qname+"e")
if e:
evt.set()
evt.clear()

@isnowfy
Copy link
Owner

isnowfy commented May 27, 2016

应该是gevent有修改导致不能序列化了,这个要想想办法,你这种改法的话导致所有请求都是一个event,我那个是一个url一个event,锁的粒度更小一些,这样改会导致速度变慢,需要想想怎么改会好一些

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants