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 custom event loop capabilites #50

Closed
wants to merge 7 commits into from

Conversation

bretttjohnson1
Copy link
Contributor

@bretttjohnson1 bretttjohnson1 commented May 10, 2018

Adds the ability to give a Server instance a custom_event_loop.

def get_event_loop(self):
if self.custom_event_loop is None:
return asyncio.get_event_loop()
else:
Copy link
Owner

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.

self.custom_event_loop = custom_event_loop

def get_event_loop(self):
if self.custom_event_loop is None:
Copy link
Owner

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:

@bmuller
Copy link
Owner

bmuller commented May 15, 2018

Hey @bretttjohnson1 - thanks for the submission! Given the ability to set an event loop explicitly in asyncio - are these modifications necessary?

@bretttjohnson1
Copy link
Contributor Author

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.

@bmuller
Copy link
Owner

bmuller commented May 15, 2018

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.

@bmuller
Copy link
Owner

bmuller commented Jan 12, 2019

Closed from inactivity. Please feel free to reopen if you still see a need and want to discuss. Thanks!

@bmuller bmuller closed this Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants