so I have an event loop that will run_until_complete my accept_connection method
@asyncio.coroutine def accept_connection(self): assert self.server_socket is not None while True: client, addr = yield from self.loop.sock_accept(self.server_socket) asyncio.async(self.handle_connection(client, addr))
My handle_connection method is as follows
def handle_connection(self, client, addr): #removed error checking while True: try: yield from asyncio.wait([con.handle_read_from_connection()], timeout=5.0) except (AssertionError, PacketException): print("Invalid packet detected!")
Finally, my handle_read_from_connection (currently) looks like this:
@asyncio.coroutine def handle_read_from_connection(self): raise PacketException("hello")
therefore, this method should always raise an error and remove the exception block from the try catch statement and output an invalid package. Instead, I get a trace!
future: Task(<handle_read_from_connection>)<exception=PacketException('hello',)> Traceback (most recent call last): File "/usr/lib/python3.4/asyncio/tasks.py", line 283, in _step result = next(coro) File "/some_path.py", line 29, in handle_read_from_connection raise PacketException("hello") GameProtocol.GameProtocol.PacketException: hello
Does anyone know what is going on here? Why does the catch attempt not work? and how can I get it so we can catch these errors.
python try-catch python-asyncio
zidsal
source share