fix(tasks): newly assigned `None
` in registry (#2381)
This commit is contained in:
parent
88bc6d8966
commit
68b654d981
|
@ -1268,10 +1268,9 @@ class Sanic(BaseSanic, RunnerMixin, metaclass=TouchUpMeta):
|
|||
...
|
||||
|
||||
def purge_tasks(self):
|
||||
for task in self.tasks:
|
||||
for key, task in self._task_registry.items():
|
||||
if task.done() or task.cancelled():
|
||||
name = task.get_name()
|
||||
self._task_registry[name] = None
|
||||
self._task_registry[key] = None
|
||||
|
||||
self._task_registry = {
|
||||
k: v for k, v in self._task_registry.items() if v is not None
|
||||
|
|
|
@ -80,6 +80,18 @@ async def test_purge_tasks(app: Sanic):
|
|||
assert len(app._task_registry) == 0
|
||||
|
||||
|
||||
async def test_purge_tasks_with_create_task(app: Sanic):
|
||||
app.add_task(asyncio.create_task(dummy(3)), name="dummy")
|
||||
|
||||
await app.cancel_task("dummy")
|
||||
|
||||
assert len(app._task_registry) == 1
|
||||
|
||||
app.purge_tasks()
|
||||
|
||||
assert len(app._task_registry) == 0
|
||||
|
||||
|
||||
def test_shutdown_tasks_on_app_stop():
|
||||
class TestSanic(Sanic):
|
||||
shutdown_tasks = Mock()
|
||||
|
|
Loading…
Reference in New Issue
Block a user