Skip to content

Commit

Permalink
Fixed expired worker thread being sometimes assigned a task
Browse files Browse the repository at this point in the history
Fixes #323.
  • Loading branch information
agronholm committed Jun 23, 2021
1 parent 5dc34a1 commit 49f666e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Version history

This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.

**UNRELEASED**

- Fixed idle thread pruning on asyncio sometimes causing an expired worker thread to be assigned a
task

**3.2.0**

- Added Python 3.10 compatibility
Expand Down
6 changes: 3 additions & 3 deletions src/anyio/_backends/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,9 @@ async def run_sync_in_worker_thread(
if now - idle_workers[0].idle_since < WorkerThread.MAX_IDLE_TIME:
break

worker = idle_workers.popleft()
worker.root_task.remove_done_callback(worker.stop)
worker.stop()
expired_worker = idle_workers.popleft()
expired_worker.root_task.remove_done_callback(expired_worker.stop)
expired_worker.stop()

worker.queue.put_nowait((func, args, future))
return await future
Expand Down

0 comments on commit 49f666e

Please sign in to comment.