run_until_complete
だから私は私のaccept_connection
方法になるイベントループを持っています
@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))
私のhandle_connection
方法は次のようになります
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!")
最後に私のhandle_read_from_connection
(現在)は次のようになります。
@asyncio.coroutine
def handle_read_from_connection(self):
raise PacketException("hello")
したがって、このメソッドは常にエラーを発生させ、try catch ステートメントの except ブロックにヒットし、検出された無効なパケットを出力する必要があります。代わりに、トレースバックが発生します。
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
ここで何が起こっているのか誰か知っていますか?try catch が機能しないのはなぜですか? これらのエラーをキャッチできるようにするにはどうすればよいですか