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

Add udp #327

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add udp #327

wants to merge 1 commit into from

Conversation

aratz-lasa
Copy link

This is the code related to UDP implementation, where it is trying to Resolve #326 .

self._stream.close()
# TODO: Correct way to destroy all handlers?
for task in self._running_handlers:
task.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper pattern here according to the asyncio docs is:

task.cancel()
try:
    await task
except asyncio.CancelledError:
    pass

This gives the loop the opportunity to inject the cancellation exception into the task so that it doesn't end up being reported as an unretrieved exception.

Copy link
Author

@aratz-lasa aratz-lasa Oct 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I missed it. And probably there are more bugs, I wrote it without much revising.

Copy link
Contributor

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to hold off on merging this until we resolve the timeline for trio. If it's to be soon, we should keep this as a reference and re-implement using trio, otherwise we can proceed if conversion to trio is likely to happen on a longer timeline.

@aratz-lasa
Copy link
Author

aratz-lasa commented Oct 16, 2019

This is still just a "prototype" of what could be a UDP implementation. I just made the pull request for being easily referable from the issue.
Are there any plans for implementing in Trio? I didn't know it.
By the way I love trio. Even though it is not easily compatible with asyncio.

@aratz-lasa aratz-lasa closed this Oct 16, 2019
@aratz-lasa aratz-lasa reopened this Oct 16, 2019
@aratz-lasa
Copy link
Author

aratz-lasa commented Oct 16, 2019

Sorry for closing @pipermerriam I was browsing on the phone, and I hit "Close and comment" accidentally.

@pipermerriam
Copy link
Contributor

Are there any plans for implementing in Trio? I didn't know it.

If you would like to work on that I'd be happy to help in any way I can. That could be reviewing pull requests, funding a small grant, etc.

@aratz-lasa
Copy link
Author

If you would like to work on that I'd be happy to help in any way I can. That could be reviewing pull requests, funding a small grant, etc.

We should first check how asyncio compatibility would work, because most people use asyncio. Or which limitations/difficulties may arise. However, I think, Trio's sockets API (apart from Nursery) are much better than asyncio's. And even more for getting a Unified Interface for TCP and UDP.

@pipermerriam
Copy link
Contributor

The plan would be to drop compatibility with asyncio, converting this to a pure trio based library.

Removed 'drain' from Stream unified interface

Linted

Linted

Fixed little ineffiencies, and added bit of documentation

Fixed ServerStream closing

With previous implementation, when you closed the stream, you closed the stream shared by all UDP handlers from the same Server

Fixed inconsistent method resolution in UDP Streams

Linted
@sevenrats
Copy link

some useful links for getting this ported to trio:
python-trio/trio#537
https://github.com/python-trio/trio/blob/master/notes-to-self/ntp-example.py

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

Successfully merging this pull request may close these issues.

Add UDP
3 participants