Skip to content

Commit

Permalink
cancel safely
Browse files Browse the repository at this point in the history
  • Loading branch information
Yostra authored and hoffmang9 committed Apr 12, 2021
1 parent 773adfa commit 06e871c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions chia/server/node_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,18 @@ async def start_tasks(self) -> None:

async def _close_common(self) -> None:
self.is_closed = True
self.connect_peers_task.cancel()
self.serialize_task.cancel()
self.cleanup_task.cancel()
self.cancel_task_safe(self.connect_peers_task)
self.cancel_task_safe(self.serialize_task)
self.cancel_task_safe(self.cleanup_task)
await self.connection.close()

def cancel_task_safe(self, task: Optional[asyncio.Task]):
if task is not None:
try:
task.cancel()
except Exception as e:
self.log.error(f"Error while canceling task.{e} {task}")

def add_message(self, message, data):
self.message_queue.put_nowait((message, data))

Expand Down

0 comments on commit 06e871c

Please sign in to comment.