Skip to content

Commit

Permalink
Use create task instead of ensure future
Browse files Browse the repository at this point in the history
  • Loading branch information
hsahovic committed Aug 25, 2022
1 parent 35717cc commit 5dd8dc0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/poke_env/player/player_network_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from abc import ABC
from abc import abstractmethod
from asyncio import CancelledError
from asyncio import ensure_future
from asyncio import create_task
from asyncio import Event
from asyncio import Lock
from asyncio import sleep
Expand Down Expand Up @@ -66,6 +66,7 @@ def __init__(
If None pings will never time out.
:type ping_timeout: float, optional
"""
self._active_tasks: set = set()
self._ping_interval = ping_interval
self._ping_timeout = ping_timeout
self._authentication_url = server_configuration.authentication_url
Expand Down Expand Up @@ -309,7 +310,10 @@ async def listen(self) -> None:
self._websocket = websocket
async for message in websocket:
self.logger.info("\033[92m\033[1m<<<\033[0m %s", message)
ensure_future(self._handle_message(message))
task = create_task(self._handle_message(message))
self._active_tasks.add(task)
task.add_done_callback(self._active_tasks.discard)

except websockets.exceptions.ConnectionClosedOK:
self.logger.warning(
"Websocket connection with %s closed", self.websocket_url
Expand Down

0 comments on commit 5dd8dc0

Please sign in to comment.