pyshark icon indicating copy to clipboard operation
pyshark copied to clipboard

Run the packet parsing event loop in a different thread.

Open md11235 opened this issue 6 years ago • 6 comments

So that pyshark can be used in Jupyter Notebooks.

The version by KimiNewt works like a charm! I've use this library heavily win python scripts run in the command line. But when this version is run in a Jupyter Notebook, it will complain:

RuntimeError: Cannot run the event loop while another loop is running

After digging around the web, based on a code snippet from @fortuna at https://github.com/ipython/ipython/issues/11030 , I've tried to come up with a little code to make pyshark run in Jupyter Notebooks.

md11235 avatar Aug 29 '18 09:08 md11235

Any progress on this? Or workaround? I am new to python multiprocessing / asyncio. Could we somehow make this patch working?

letalvoj avatar Mar 12 '19 13:03 letalvoj

+1 on being really interested in a solution. Not being able to run pyshark from within a Jupyter Notebook is really annoying... I'm not in a position to say whether this pull request will have any negative side effects, but I'd appreciate a lot of someone could look into integrating it if it's all good.

jkbecker avatar Apr 29 '19 19:04 jkbecker

This patch is so important for my workflow that I'm using md11235's fork of pyshark now. Thanks md11235!

jjoonathan avatar May 07 '19 20:05 jjoonathan

I am using a workaround for now with nest_asyncio package. import nest_asyncio nest_asyncio.apply()

Although I would be interested to see if there is a solution that can be integrated within pyshark.

salijona avatar Aug 26 '19 13:08 salijona

Jupyter can run it now, assuming you exclusively use the async methods. I'll try to work on adding the missing ones but you can use ones like cap.packets_from_tshark inside jupyter.

nest_asyncio is also an interesting solution, I'll look into that.

KimiNewt avatar Aug 26 '19 14:08 KimiNewt

Any progress on the PR? If this works now, we should close this!

XChikuX avatar Jan 31 '23 07:01 XChikuX