Skip to content

Commit

Permalink
Reraise app exceptions with the correct traceback
Browse files Browse the repository at this point in the history
Fixes #49
  • Loading branch information
miguelgrinberg committed May 31, 2017
1 parent 90944b9 commit 66b8f5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
15 changes: 8 additions & 7 deletions engineio/asyncio_socket.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import time
import six
import sys
import time

from . import exceptions
from . import packet
Expand Down Expand Up @@ -96,15 +97,15 @@ async def close(self, wait=True, abort=False):
reraise_exc = None
try:
await self.server._trigger_event('disconnect', self.sid)
except Exception as e:
reraise_exc = e
except:
reraise_exc = sys.exc_info()
if not abort:
await self.send(packet.Packet(packet.CLOSE))
self.closed = True
if wait:
await self.queue.join()
if reraise_exc:
raise reraise_exc
six.reraise(*reraise_exc)

async def _upgrade_websocket(self, environ):
"""Upgrade the connection from polling to websocket."""
Expand Down Expand Up @@ -198,15 +199,15 @@ async def writer():
await self.receive(pkt)
except exceptions.UnknownPacketError:
pass
except Exception as e:
except:
# if we get an unexpected exception (such as something in an
# application event handler) we close the connection properly
# and then reraise the exception
reraise_exc = e
reraise_exc = sys.exc_info()
break

await self.queue.put(None) # unlock the writer task so it can exit
await asyncio.wait_for(writer_task, timeout=None)
await self.close(wait=True, abort=True)
if reraise_exc:
raise reraise_exc
six.reraise(*reraise_exc)
15 changes: 8 additions & 7 deletions engineio/socket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
import six
import sys
import time

from . import exceptions
from . import packet
Expand Down Expand Up @@ -112,15 +113,15 @@ def close(self, wait=True, abort=False):
reraise_exc = None
try:
self.server._trigger_event('disconnect', self.sid, async=False)
except Exception as e:
reraise_exc = e
except:
reraise_exc = sys.exc_info()
if not abort:
self.send(packet.Packet(packet.CLOSE))
self.closed = True
if wait:
self.queue.join()
if reraise_exc:
raise reraise_exc
six.reraise(*reraise_exc)

def _upgrade_websocket(self, environ, start_response):
"""Upgrade the connection from polling to websocket."""
Expand Down Expand Up @@ -216,17 +217,17 @@ def writer():
self.receive(pkt)
except exceptions.UnknownPacketError:
pass
except Exception as e:
except:
# if we get an unexpected exception (such as something in an
# application event handler) we close the connection properly
# and then reraise the exception
reraise_exc = e
reraise_exc = sys.exc_info()
break

self.queue.put(None) # unlock the writer task so that it can exit
writer_task.join()
self.close(wait=True, abort=True)
if reraise_exc:
raise reraise_exc
six.reraise(*reraise_exc)

return []

0 comments on commit 66b8f5d

Please sign in to comment.