so I have an event loop which 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 looks like this
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 hit the except block of the try catch statement and print invalid packet detected. Instead what happens is I get a traceback!
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 going on here? why is the try catch not working? and how can I get it so we can catch these errors