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

@python3.5 - Fix saving/loading state #37

Merged
merged 7 commits into from
Oct 16, 2017
Merged

Conversation

vdrg
Copy link
Contributor

@vdrg 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)

loop = LoopingCall(self.saveState, fname)
loop.start(frequency)
return loop
asyncio.ensure_future(self._saveStateRegularly(fname))
Copy link
Owner

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?

Copy link
Owner

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)?

Copy link
Contributor Author

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 🙃 .

Copy link
Owner

Choose a reason for hiding this comment

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

No worries!

@@ -48,6 +48,9 @@ def stop(self):
if self.transport is not None:
self.transport.close()

if self.save_state_loop is not None:
Copy link
Owner

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:

Copy link
Contributor Author

@vdrg vdrg Oct 16, 2017

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!

Copy link
Owner

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.

Copy link
Contributor Author

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.

@bmuller bmuller merged commit a6e50ac into bmuller:python3.5 Oct 16, 2017
@bmuller
Copy link
Owner

bmuller commented Oct 16, 2017

Thanks for the help!

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.

None yet

2 participants