-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
@python3.5 - Fix saving/loading state #37
Conversation
vdrg
commented
Oct 15, 2017
- pickle needed to open the file with 'wb'/'rb' permissions.
- use asyncio for saveStateRegularly (it was using a Twisted function)
kademlia/network.py
Outdated
loop = LoopingCall(self.saveState, fname) | ||
loop.start(frequency) | ||
return loop | ||
asyncio.ensure_future(self._saveStateRegularly(fname)) |
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.
Not sure why this line is here - what are you looking to do here?
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.
Could you just make this a call to self.saveState(fname)
?
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.
You are totally right! I'm sorry, I've never used asyncio before 🙃 .
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.
No worries!
kademlia/network.py
Outdated
@@ -48,6 +48,9 @@ def stop(self): | |||
if self.transport is not None: | |||
self.transport.close() | |||
|
|||
if self.save_state_loop is not 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.
This can just be if self.save_state_loop:
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.
I did that so that it was consistent with the previous ones. Also, isn't "is not None" the more "idiomatic" way to do it?
Let me know if I should update the previous ones too!
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.
I think the idiomatic way would be to initialize self.save_state_loop = None
in the constructor, and then to use just if self.save_state_loop
since it will either be a Future
or 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.
Perfect, thanks. I've just pushed it, and also changed the check for "refresh_loop" as it will also be either a Future
or None
.
Thanks for the help! |