Skip to content

Commit c89fc6e

Browse files
authored
Merge pull request #670 from matan1008/bugfix/ensure-close-async
capture: Fix close_async in case the stderr task is still running
2 parents 5bef368 + 4a729cf commit c89fc6e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/pyshark/capture/capture.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import contextlib
23
import inspect
34
import os
45
import threading
@@ -402,7 +403,10 @@ async def close_async(self):
402403
self._running_processes.clear()
403404

404405
# Wait for all stderr handling to finish
405-
await asyncio.gather(*self._stderr_handling_tasks)
406+
for task in self._stderr_handling_tasks:
407+
task.cancel()
408+
with contextlib.suppress(asyncio.CancelledError):
409+
await task
406410

407411
def __del__(self):
408412
if self._running_processes:

0 commit comments

Comments
 (0)