Skip to content

Commit

Permalink
Enable exiting the session
Browse files Browse the repository at this point in the history
  • Loading branch information
tfarago committed Feb 13, 2015
1 parent a3c311b commit 47861c7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions concert/session/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import math
import os
import inspect
import subprocess
import time
Expand Down Expand Up @@ -149,16 +150,18 @@ def abort():


@threaded
def check_emergency_stop(check, poll_interval=0.1*q.s):
def check_emergency_stop(check, poll_interval=0.1*q.s, exit_session=False):
"""If a callable *check* returns True abort is called. Then until it clears to False nothing is
done and then the process begins again. *poll_interval* is the interval at which *check* is
called.
called. If *exit_session* is True the session exits when the emergency stop occurs.
"""
while True:
if check():
futures = abort()
LOG.error('Emergency stop')
wait(futures)
if exit_session:
os.abort()
while check():
# Wait until the flag clears
time.sleep(poll_interval.to(q.s).magnitude)
Expand Down

1 comment on commit 47861c7

@tfarago
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is necessary if you want to prevent Concert from continuing doing anything it was doing before the emergency stop (another user request).
This is a hard core implementation but I don't see a safer solution right now. If we have threads around (which we do if we don't use gevent) they will just happily continue after any attempt we do to close IPython politely. I tried many variants and nothing worked so far.

Please sign in to comment.