python - IMAP and Gevent: ConcurrentObjectUseError -


i'm trying create asynchronous download of messages e-mail gevent , imap. use python 2.7.8 , gevent 1.1.1.

self.connection = imaplib.imap4_ssl(self.hostname, self.port, **ssl_files)  ...  rv, data = self.connection.search(none, "all") numbers = [number number in data[0].split()]  threads = [gevent.spawn(self._get_message, message) message in numbers] gevent.joinall(threads) 

function _get_message have code:

def _get_message(self, message_number):     logging.info("message {0} called!".format(message_number))     rv, data = self.connection.fetch(message_number, '(rfc822)')     if not self.is_ok(rv): return     message = email.message_from_string(data[0][1]) 

but every time have error:

traceback (most recent call last):   file "c:\python27\lib\site-packages\gevent\greenlet.py", line 534, in run     result = self._run(*self.args, **self.kwargs)   file "c:/users/eugene/pycharmprojects/extract email criteria/imap_email.py", line 108, in _get_message     rv, data = self.connection.fetch(message_number, '(rfc822)')   file "c:\python27\lib\imaplib.py", line 456, in fetch     typ, dat = self._simple_command(name, message_set, message_parts)   file "c:\python27\lib\imaplib.py", line 1088, in _simple_command     return self._command_complete(name, self._command(name, *args))   file "c:\python27\lib\imaplib.py", line 910, in _command_complete     typ, data = self._get_tagged_response(tag)   file "c:\python27\lib\imaplib.py", line 1017, in _get_tagged_response     self._get_response()   file "c:\python27\lib\imaplib.py", line 929, in _get_response     resp = self._get_line()   file "c:\python27\lib\imaplib.py", line 1027, in _get_line     line = self.readline()   file "c:\python27\lib\imaplib.py", line 1189, in readline     return self.file.readline()   file "c:\python27\lib\socket.py", line 451, in readline     data = self._sock.recv(self._rbufsize)   file "c:\python27\lib\site-packages\gevent\_sslgte279.py", line 455, in recv     return self.read(buflen)   file "c:\python27\lib\site-packages\gevent\_sslgte279.py", line 314, in read     self._wait(self._read_event, timeout_exc=_sslerrorreadtimeout)   file "c:\python27\lib\site-packages\gevent\_socket2.py", line 173, in _wait     raise _socketcommon.concurrentobjectuseerror('this socket used greenlet: %r' % (watcher.callback, )) concurrentobjectuseerror: socket used greenlet: <bound method waiter.switch of <gevent.hub.waiter object @ 0x02b1c558>> <greenlet @ 0x2afe710: <bound method emailimapconnection._get_message of <__main__.emailimapconnection object @ 0x02a63c50>>(4)> failed concurrentobjectuseerror 

code on github gist: https://gist.github.com/gitex/0d9385fa3ab1d98f30713f6eeeab454f

i have monkey.patch_all() in beginning. works first socket, rest locked. assume socket blocked inside imap. how can solve problem?


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -