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

Implement BaseService.run_task(awaitable) #1173

Merged
merged 2 commits into from Aug 13, 2018

Conversation

gsalgado
Copy link
Collaborator

It runs the given awaitable in the background, catches/ignores
OperationCancelled and ensures the task is finished before the
service is finished.

Also removes trinity.Node.add_service() as the same
functionality is provided by BaseService.run_child_service()

Closes: #1118

Copy link
Contributor

@cburgdorf cburgdorf left a comment

Choose a reason for hiding this comment

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

LGTM

@gsalgado gsalgado force-pushed the issue-1118 branch 2 times, most recently from 65b1f59 to c0d19de Compare August 13, 2018 14:52
Copy link
Member

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

Let me know if I'm wrong about the O(n) memory footprint for the _tasks API.

await awaitable
except OperationCancelled:
pass
self._tasks.add(asyncio.ensure_future(f()))
Copy link
Member

Choose a reason for hiding this comment

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

I'm not seeing anywhere that we cleanup finished tasks. Things like Discovery.mayber_connect_to_more_peers which run periodically will result in an ever growing memory footprint. It looks like we need something to do periodic garbage collection for tasks that are complete.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's why I used a WeakSet for self._tasks; once a task is done there should be no strong reference to it left, and then it is discarded from the set.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

That's fancy! 👍

It runs the given awaitable in the background, catches/ignores
OperationCancelled and ensures the task is finished before the
service is finished.

Also removes trinity.Node.add_service() as the same
functionality is provided by BaseService.run_child_service()

Closes: ethereum#1118
It's no longer needed as of the previous commit
@gsalgado gsalgado merged commit dd17bd0 into ethereum:master Aug 13, 2018
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

3 participants