Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions aiomultiprocess/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,28 @@ def terminate(self) -> None:
for process in self.processes:
process.terminate()

# Remove all remaining work in the queues, since otherwise this will
# prevent proper exit while multiprocessing waits until the threads
# associated with the queue has terminated, and that thread itself is
# waiting for queues to empty (but the processes have exited, so will
# not be doing the work).
for (tx, rx) in self.queues.values():
while True:
try:
_ = tx.get_nowait()
except queue.Empty:
break
tx.close()

while True:
try:
_ = rx.get_nowait()
except queue.Empty:
break
rx.close()

self.queues = {}

async def join(self) -> None:
"""Wait for the pool to finish gracefully."""
if self.running:
Expand Down