Running the following python 3.10.12 code on Ubuntu 22.04.4 using pyshark
0.6 seems to ignore the try-except
statement of python:
<code>capture = pyshark.FileCapture(filename)
try:
for packet in capture:
pass
except:
print("exception")
</code>
<code>capture = pyshark.FileCapture(filename)
try:
for packet in capture:
pass
except:
print("exception")
</code>
capture = pyshark.FileCapture(filename)
try:
for packet in capture:
pass
except:
print("exception")
Even I enclosed the reading loop in a try-except
statement I get the following output:
<code>exception
Exception ignored in: <function Capture.__del__ at 0x79b5be57c3a0>
Traceback (most recent call last):
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 405, in __del__
self.close()
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 393, in close
self.eventloop.run_until_complete(self.close_async())
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 397, in close_async
await self._cleanup_subprocess(process)
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 379, in _cleanup_subprocess
raise TSharkCrashException(f"TShark (pid {process.pid}) seems to have crashed (retcode: {process.returncode}).n"
pyshark.capture.capture.TSharkCrashException: TShark (pid 8097) seems to have crashed (retcode: 2).
Last error line: tshark: The file "/home/alex/Work/Data/test.pcap" appears to have been cut short in the middle of a packet.
Try rerunning in debug mode [ capture_obj.set_debug() ] or try updating tshark.
</code>
<code>exception
Exception ignored in: <function Capture.__del__ at 0x79b5be57c3a0>
Traceback (most recent call last):
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 405, in __del__
self.close()
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 393, in close
self.eventloop.run_until_complete(self.close_async())
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 397, in close_async
await self._cleanup_subprocess(process)
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 379, in _cleanup_subprocess
raise TSharkCrashException(f"TShark (pid {process.pid}) seems to have crashed (retcode: {process.returncode}).n"
pyshark.capture.capture.TSharkCrashException: TShark (pid 8097) seems to have crashed (retcode: 2).
Last error line: tshark: The file "/home/alex/Work/Data/test.pcap" appears to have been cut short in the middle of a packet.
Try rerunning in debug mode [ capture_obj.set_debug() ] or try updating tshark.
</code>
exception
Exception ignored in: <function Capture.__del__ at 0x79b5be57c3a0>
Traceback (most recent call last):
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 405, in __del__
self.close()
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 393, in close
self.eventloop.run_until_complete(self.close_async())
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 397, in close_async
await self._cleanup_subprocess(process)
File "/home/alex/.local/lib/python3.10/site-packages/pyshark/capture/capture.py", line 379, in _cleanup_subprocess
raise TSharkCrashException(f"TShark (pid {process.pid}) seems to have crashed (retcode: {process.returncode}).n"
pyshark.capture.capture.TSharkCrashException: TShark (pid 8097) seems to have crashed (retcode: 2).
Last error line: tshark: The file "/home/alex/Work/Data/test.pcap" appears to have been cut short in the middle of a packet.
Try rerunning in debug mode [ capture_obj.set_debug() ] or try updating tshark.
How to suppress this output?
To clarify: I am not interested to fix any problem or error. I am just interested into suppressing this output of the exception!