Skip to content

Commit c014973

Browse files
bugfix
1 parent bcf7dbe commit c014973

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/poke_env/player/env.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,24 @@ def get_timeout(self, timeout_flag: asyncio.Event) -> Optional[ItemType]:
5656
asyncio.ensure_future(self.async_get(), loop=self.loop),
5757
asyncio.ensure_future(asyncio.wait_for(timeout_flag.wait(), timeout=10), loop=self.loop),
5858
]
59-
done, pending = asyncio.run_coroutine_threadsafe(
60-
asyncio.wait(
61-
tasks,
62-
return_when=asyncio.FIRST_COMPLETED,
63-
),
64-
self.loop,
65-
).result()
66-
for task in pending:
67-
task.cancel()
68-
result = list(done)[0].result()
69-
timeout_flag.clear()
70-
if result is True:
59+
try:
60+
done, pending = asyncio.run_coroutine_threadsafe(
61+
asyncio.wait(
62+
tasks,
63+
return_when=asyncio.FIRST_COMPLETED,
64+
),
65+
self.loop,
66+
).result()
67+
for task in pending:
68+
task.cancel()
69+
result = list(done)[0].result()
70+
timeout_flag.clear()
71+
if result is True:
72+
return None
73+
else:
74+
return result
75+
except asyncio.exceptions.TimeoutError:
7176
return None
72-
else:
73-
return result
7477

7578
async def async_put(self, item: ItemType):
7679
await self.queue.put(item)

0 commit comments

Comments
 (0)