From 7142c5bf88abcd4c65c81052a00226d6155dda42 Mon Sep 17 00:00:00 2001 From: Matan Perelman Date: Thu, 2 Nov 2023 20:44:59 +0200 Subject: [PATCH] capture: Fix close_async in case the stderr task is still running --- src/pyshark/capture/capture.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pyshark/capture/capture.py b/src/pyshark/capture/capture.py index 31fcd2a4..0a7037e5 100644 --- a/src/pyshark/capture/capture.py +++ b/src/pyshark/capture/capture.py @@ -1,4 +1,5 @@ import asyncio +import contextlib import os import threading import subprocess @@ -398,7 +399,10 @@ async def close_async(self): self._running_processes.clear() # Wait for all stderr handling to finish - await asyncio.gather(*self._stderr_handling_tasks) + for task in self._stderr_handling_tasks: + task.cancel() + with contextlib.suppress(asyncio.CancelledError): + await task def __del__(self): if self._running_processes: