Add loop helpers and simplify deploy example #46

Merged
merged 1 commit into from Jan 17, 2017

Conversation

Projects
None yet
2 participants
Member

johnsca commented Jan 12, 2017

No description provided.

examples/deploy.py
-loop.set_debug(False)
-loop.create_task(run())
-loop.run_forever()
+loop.run(main)
@tvansteenburgh

tvansteenburgh Jan 12, 2017

Member

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

@johnsca

johnsca Jan 13, 2017

Member

Yes. Yes it should.

Member

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
juju/loop.py
+ loop.set_debug(debug)
+ if interruptable:
+ for signame in ('SIGINT', 'SIGTERM'):
+ loop.add_signal_handler(getattr(signal, signame), stop_loop)
@tvansteenburgh

tvansteenburgh Jan 13, 2017

Member

stop_loop could be changed to loop.stop

Member

tvansteenburgh commented Jan 13, 2017

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.

Member

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.

Member

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.

Member

tvansteenburgh commented Jan 17, 2017

LGTM, thanks @johnsca

@tvansteenburgh tvansteenburgh merged commit 686b6f4 into master Jan 17, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@tvansteenburgh tvansteenburgh deleted the feature/loop-helper branch Jan 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment