Handling KeyboardInterrupt?

22 views
Skip to first unread message

Eddie Parker

unread,
Feb 19, 2022, 6:34:16 AM2/19/22
to python-doit
Hello!

I'm loving doit so far, it's great for automating what otherwise would be a gnarly batch file or set of batch files.  So thanks everyone!

That said, I do use doit to launch a flask webserver, that can only be terminated via CTRL-C.  In doing so however any output I may have gets ran off the screen in showing the traceback from the KeyboardInterrupt:

INFO:werkzeug: * Debugger PIN: 320-533-594
INFO:werkzeug: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
The process cannot access the file because it is being used by another process.
Traceback (most recent call last):
  File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\dev\personal\tensorflask\venv\Scripts\doit.exe\__main__.py", line 7, in <module>
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\__main__.py", line 8, in main
    sys.exit(DoitMain().run(sys.argv[1:]))
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\doit_cmd.py", line 295, in run
    return command.parse_execute(args)
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\cmd_base.py", line 151, in parse_execute
    return self.execute(params, args)
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\cmd_base.py", line 605, in execute
    return self._execute(**exec_params)
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\cmd_run.py", line 265, in _execute
    return runner.run_all(self.control.task_dispatcher())
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\runner.py", line 255, in run_all
    self.run_tasks(task_dispatcher)
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\runner.py", line 221, in run_tasks
    catched_excp = self.execute_task(node.task)
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\runner.py", line 176, in execute_task
    return task.execute(self.stream)
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\task.py", line 466, in execute
    action_return = action.execute(task_stdout, task_stderr)
  File "D:\dev\personal\tensorflask\venv\lib\site-packages\doit\action.py", line 232, in execute
    t_out.join()
  File "C:\Python310\lib\threading.py", line 1089, in join
    self._wait_for_tstate_lock()
  File "C:\Python310\lib\threading.py", line 1109, in _wait_for_tstate_lock
    if lock.acquire(block, timeout):
KeyboardInterrupt

Anyhow: I'm happy to implement this and submit a PR: but I'd love it if KeyboardInterrupt was just silently handled, probably returning a non-zero error code in case doit.py is used as part of a script.  Does this sound reasonable?

Eduardo Schettino

unread,
Feb 19, 2022, 6:44:28 AM2/19/22
to python-doit
On Sat, Feb 19, 2022 at 7:34 PM Eddie Parker <eddie...@gmail.com> wrote:
Hello!

I'm loving doit so far, it's great for automating what otherwise would be a gnarly batch file or set of batch files.  So thanks everyone!
Cool
 

That said, I do use doit to launch a flask webserver, that can only be terminated via CTRL-C.  In doing so however any output I may have gets ran off the screen in showing the traceback from the KeyboardInterrupt:

I guess using a "LongRunning" action already solves your problem.
 

Anyhow: I'm happy to implement this and submit a PR: but I'd love it if KeyboardInterrupt was just silently handled, probably returning a non-zero error code in case doit.py is used as part of a script.  Does this sound reasonable?

doit is a tool for developers. I would not like doit to silently swallow exceptions by default ... even on CTRL-C 

But if you would like to contribute some code that are lots of issues that need attention :)

Regards

Eddie Parker

unread,
Mar 16, 2022, 2:55:23 PM3/16/22
to python-doit
Ah, shame.  That KeyboardInterrupt is very long and hides a bunch of potentially useful information when I obviously know that I did a keyboard interrupt. :)

I definitely will look at contributing some code, but forgive me if I try to align with work that best suits my workflow - time is a currency, after all. :)

-e-

Reply all
Reply to author
Forward
0 new messages