Skip to content

Commit

Permalink
refact: give Scheduler a close() method
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jun 24, 2024
1 parent 89d2436 commit ff4ecea
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pyftpdlib/ioloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ def reheapify(self):
self._tasks = [x for x in self._tasks if not x.cancelled]
heapq.heapify(self._tasks)

def close(self):
for x in self._tasks:
try:
if not x.cancelled:
x.cancel()
except Exception:
logger.error(traceback.format_exc())
del self._tasks[:]
self._cancellations = 0


class _CallLater:
"""Container object which instance is returned by ioloop.call_later()."""
Expand Down Expand Up @@ -417,13 +427,7 @@ def close(self):
self.socket_map.clear()

# free scheduled functions
for x in self.sched._tasks:
try:
if not x.cancelled:
x.cancel()
except Exception:
logger.error(traceback.format_exc())
del self.sched._tasks[:]
self.sched.close()


# ===================================================================
Expand Down

0 comments on commit ff4ecea

Please sign in to comment.