Skip to content
Snippets Groups Projects
Commit f62fc958 authored by Damian Johnson's avatar Damian Johnson
Browse files

Allow interpreter to continue after tor shutsdown

When tor shuts down the next tor-prompt command immediately terminates the
interpreter. This is both unnecessary and sucks. We provide more than a control
connection and should let users continue to issue those commans after tor's
gone.

  https://www.atagar.com/transfer/stem/interpreter_shutdown_prompt.png

Neat idea suggested by teor...

  https://trac.torproject.org/projects/tor/ticket/22374
parent 56f2cf19
No related branches found
No related tags found
No related merge requests found
......@@ -72,6 +72,7 @@ The following are only available within Stem's `git repository
* **Interpreter**
* Added a `'--run [command or path]' argument <tutorials/down_the_rabbit_hole.html#running-individual-commands>`_ to invoke specific commands (:trac:`21541`)
* Allowing interpreter to continue after tor shutsdown (:trac:`22374`)
.. _version_1.5:
......
......@@ -124,6 +124,7 @@ def main():
readline.set_completer_delims('\n')
interpreter = stem.interpreter.commands.ControlInterpreter(controller)
showed_close_confirmation = False
if args.run_cmd:
if args.run_cmd.upper().startswith('SETEVENTS '):
......@@ -168,6 +169,18 @@ def main():
prompt = '... ' if interpreter.is_multiline_context else PROMPT
user_input = input(prompt) if stem.prereq.is_python_3() else raw_input(prompt)
interpreter.run_command(user_input, print_response = True)
except stem.SocketClosed as exc:
if showed_close_confirmation:
print(format("Unable to run tor commands. The control connection has been closed.", *ERROR_OUTPUT))
else:
prompt = format("Tor's control port has closed. Do you want to continue this interpreter? (y/n) ", *HEADER_BOLD_OUTPUT)
user_input = input(prompt) if stem.prereq.is_python_3() else raw_input(prompt)
print('') # blank line
if user_input.lower() in ('y', 'yes'):
showed_close_confirmation = True
else:
break
except (KeyboardInterrupt, EOFError, stem.SocketClosed) as exc:
print('') # move cursor to the following line
break
......@@ -309,9 +309,6 @@ class ControlInterpreter(code.InteractiveConsole):
:raises: **stem.SocketClosed** if the control connection has been severed
"""
if not self._controller.is_alive():
raise stem.SocketClosed()
# Commands fall into three categories:
#
# * Interpreter commands. These start with a '/'.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment