ironport / shrapnel

Shrapnel is a scalable, high-performance cooperative threading library for Python.
Other
219 stars 34 forks source link

http client fails to handle errors properly #42

Open ghost opened 11 years ago

ghost commented 11 years ago

This may be similar to issue #39. Any exceptions raised during asynchronous operation can't be trapped using try/except. Using set_exception_notifier(...) works though.

I think this is because client.read_thread() method fails to capture and handle exceptions when calling client._read_message(). Further, request and latch objects miss any exception handling functionality.

The following hack worked for me:

from coro.http.client import client as http_client

class http_kludge(http_client):

    def read_thread(self):
        while 1:
            req = self.pending.pop()
            if req is None:
                break
            else:
                try:
                    self._read_message(req)
                except Exception, exc:
                    req.latch.cv.raise_all(exc) # put the exception where it belongs
                else:
                    if not req.response:
                        break
                    else:
                        req.wake()