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 loop helpers and simplify deploy example #46

Merged
merged 1 commit into from Jan 17, 2017

Conversation

johnsca
Copy link
Contributor

@johnsca johnsca commented Jan 12, 2017

No description provided.

loop.set_debug(False)
loop.create_task(run())
loop.run_forever()
loop.run(main)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be loop.run(main()) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Yes it should.

@johnsca
Copy link
Contributor Author

johnsca commented Jan 13, 2017

The interrupt handling doesn't work like I expected and we get a bunch of error dumps. Also now getting an error on normal run that I don't understand:

Connecting to model
Deploying ubuntu
Waiting for active
Removing ubuntu
Disconnecting from model
Exception ignored in: <bound method BaseEventLoop.__del__ of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/base_events.py", line 431, in __del__
  File "/usr/lib/python3.5/asyncio/unix_events.py", line 58, in close
  File "/usr/lib/python3.5/asyncio/unix_events.py", line 139, in remove_signal_handler
  File "/usr/lib/python3.5/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

loop.set_debug(debug)
if interruptable:
for signame in ('SIGINT', 'SIGTERM'):
loop.add_signal_handler(getattr(signal, signame), stop_loop)
Copy link
Contributor

Choose a reason for hiding this comment

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

stop_loop could be changed to loop.stop

@tvansteenburgh
Copy link
Contributor

I don't really understand the "signal handler must be callable" error either. Regarding errors at termination, I assume those are coming from still-running coroutines. You'll always get tracebacks if you stop the loop while any coroutines are still running. You can try canceling all running coroutines in your signal handler.

@johnsca
Copy link
Contributor Author

johnsca commented Jan 13, 2017

@tvansteenburgh I tried cancelling the coroutines in various ways but couldn't avoid the errors, which is actually why I had the separate stop_loop functionality. I added one of my attempts to this PR, but it doesn't help.

@johnsca
Copy link
Contributor Author

johnsca commented Jan 17, 2017

I got it working gracefully and (had to) boiled it down to a single helper function instead of split across three.

@tvansteenburgh
Copy link
Contributor

LGTM, thanks @johnsca

@tvansteenburgh tvansteenburgh merged commit 686b6f4 into master Jan 17, 2017
@tvansteenburgh tvansteenburgh deleted the feature/loop-helper branch January 17, 2017 22:32
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