mtr-packet-python icon indicating copy to clipboard operation
mtr-packet-python copied to clipboard

Modernizing `asyncio` usage in examples

Open goodboy opened this issue 2 years ago • 5 comments

Would this be something you'd accept as a PR?

For example making changes like:

  • flipping loop.run_until_complete() to asyncio.run()
  • using the new taskgroups from 3.11
  • swapping .ensure_future() with the newer asyncio.create_task() where you'd prefer to not use task groups.

Super dope lib btw 😎

Lookin forward to using it in a serious project 🏄🏼

goodboy avatar Aug 10 '23 16:08 goodboy

Ah and just to justify this request, for our use case we will be deploying the probe tasks as part of existing mostly trio oriented runtime stack which demands end2end structurred concurrency (SC) 😄

goodboy avatar Aug 10 '23 16:08 goodboy

I'd prefer to keep everything compatible with other compatible with older versions of Python, unless there is some compelling reason to do otherwise. I explicitly wrote the code to be compatible as far back as Python 3.5.

I don't really understand the implications of your second comment. Is there some reason that this module is unsuitable for your purposes as-is?

matt-kimball avatar Aug 10 '23 16:08 matt-kimball

I don't really understand the implications of your second comment. Is there some reason that this module is unsuitable for your purposes as-is?

Not particularly, but it could be more compatible by leveraging the task groups in terms of errors due to connectivity failures; error bubbling is easier to capture when SC constraints are in place. It's more like the style would be more compatible and would require less workarounds in our client code.

FWIW i'm only proposing changing come examples, we could even just have a 3.11+ version of the particular use we have.

I explicitly wrote the code to be compatible as far back as Python 3.5.

👍🏼 totally get it.

goodboy avatar Aug 10 '23 16:08 goodboy

Oh also, fwiw asyncio.create_task() is from 3.7+

screenshot-2023-08-10_12-45-00

goodboy avatar Aug 10 '23 16:08 goodboy

If you want to open a PR adding a new example in the style you think is best for modern Python usage, that seems reasonable. I'd like to keep the existing ones compatible with Python 3.5.

matt-kimball avatar Aug 10 '23 16:08 matt-kimball