Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting threaded code to asyncio #40

Closed
KimiNewt opened this issue Sep 12, 2014 · 2 comments
Closed

Converting threaded code to asyncio #40

KimiNewt opened this issue Sep 12, 2014 · 2 comments
Labels

Comments

@KimiNewt
Copy link
Owner

I've been thinking of converting the code revolving around reading from the tshark subprocess (and parsing the xml) from its current state (threads) into the far-better async io paradigm.

Particularly, I thought about using asyncio (the trollius version, to keep py2.7 support) which has good support for reading from subprocesses, even on Windows. I have a basic implementation working already.

I pose this question because converting to asyncio may hurt the "interactive" usage of the package, as eventloops don't work well with them and so code like:

for packet in cap:
    # Do something with packet

May turn into something more like:

cap.for_each_packet(do_something_with_packet_callback)
# This will now block and call the function for each packet.

Though something can be implemented to still perform the interactivity and simple code as above, it will require to constantly start and stop the event loop, which might be okay if you're working interactively.

The advantages to this sort of approach is twofold:

  • Easy insertion of pyshark into other packages that work with eventloops (be it asyncio, twisted, tornado..)
  • Removing the issues and uncertainty (which you can see in past issues) that comes with threads.

I'd be happy to hear any opinions on the matter.

@KimiNewt
Copy link
Owner Author

I created a branch and a pull request for the new version (not fully working yet): #41
Comments can go there

@bbayles
Copy link
Collaborator

bbayles commented Sep 13, 2014

I played with this a bit, as you mentioned. Not being very familiar with Twisted-style programming, I thought it could be possible to integrate that with pyshark as-is.

The more I read the more I found warnings that aysnc-style code is hard to bolt onto non-async code - the reactor pattern just doesn't fit well with other patterns. But I'll give your version a whirl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants