-
-
Notifications
You must be signed in to change notification settings - Fork 210
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 custom event loop capabilites #50
Conversation
For use in running 2 separate asyncio event loops. As an example: an asyncio needs to start a server from a coroutine.
kademlia/network.py
Outdated
def get_event_loop(self): | ||
if self.custom_event_loop is None: | ||
return asyncio.get_event_loop() | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @bretttjohnson1 - the else
here is unnecessary.
kademlia/network.py
Outdated
self.custom_event_loop = custom_event_loop | ||
|
||
def get_event_loop(self): | ||
if self.custom_event_loop is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @bretttjohnson1 - this can just be if not self.custom_event_loop:
Hey @bretttjohnson1 - thanks for the submission! Given the ability to set an event loop explicitly in asyncio - are these modifications necessary? |
Hi bmuller. A problem I ran into when using kademlia was the inablilty to start a DHT when the event loop was running. This could be accomplished by creating a second event loop and passing that into the server. This is not the same as setting a different event loop as that just changes the main event loop. My changes allow for a second event loop. |
Hey @bretttjohnson1 - you should be able to start the DHT in a running event loop (it just has to be as the result of some event, i.e. a timer or external input etc etc). Unless you're doing something odd like starting a new thread with it's own event loop (in which case, you should be able to use asyncio's get_event_loop) then you should really only be using a single event loop. I'd be happy to look at some example code if you have it. |
Closed from inactivity. Please feel free to reopen if you still see a need and want to discuss. Thanks! |
Adds the ability to give a Server instance a custom_event_loop.