Skip to content

Fix Ctrl-C leaving session unexpectingly

Related to #4158

I found a way for Ctrl-c to exit bliss session, here is a simple patch to reproduce:

diff --git a/bliss/shell/cli/no_thread_repl.py b/bliss/shell/cli/no_thread_repl.py
index a609698c1..e1347c718 100644
--- a/bliss/shell/cli/no_thread_repl.py
+++ b/bliss/shell/cli/no_thread_repl.py
@@ -166,14 +166,19 @@ class NoThreadPythonRepl(PythonRepl):
# Eval.
self._current_eval_g = self.eval_greenlet(text)
+                    print("arming time bomb")
try:
+                        print("running to the shelter")
await asyncio_gevent.greenlet_to_future(self._current_eval_g)
+                        print("running...")
except asyncio.CancelledError:
pass
-
+                    print("still running...")
try:
+                        print("i'm safe now !")
result = self._current_eval_g.get()
except KeyboardInterrupt:
+                        print("[BOOM] I don't care !!!")
# should not happen here...
result = None
diff --git a/bliss/shell/cli/repl.py b/bliss/shell/cli/repl.py
index 4ee9f1303..946f211ce 100644
--- a/bliss/shell/cli/repl.py
+++ b/bliss/shell/cli/repl.py
@@ -667,6 +667,7 @@ class BlissReplBase(NoThreadPythonRepl):
logging.getLogger("user_input").info(text)
elogbook.command(text)
result = None
+        raise KeyboardInterrupt
try:
with self.app.output.capture_stdout:
result = self.raw_eval(text)

Results:

TEST_SESSION [1]: wa()
arming time bomb
running to the shelter
running...
still running...
i'm safe now !
[BOOM] I don't care !!!
TEST_SESSION [2]: wa()
arming time bomb
running to the shelter
Traceback (most recent call last):
File "/home/felix/miniconda3/envs/bliss/bin/bliss", line 8, in <module>
sys.exit(main())
File "/home/felix/projects/bliss/bliss/shell/main.py", line 232, in main
embed(
File "/home/felix/projects/bliss/bliss/shell/cli/repl.py", line 965, in embed
asyncio.run(cmd_line_i.run_async())
File "/home/felix/miniconda3/envs/bliss/lib/python3.9/asyncio/runners.py", line 47, in run
_cancel_all_tasks(loop)
File "/home/felix/miniconda3/envs/bliss/lib/python3.9/asyncio/runners.py", line 63, in _cancel_all_tasks
loop.run_until_complete(
File "/home/felix/miniconda3/envs/bliss/lib/python3.9/asyncio/base_events.py", line 634, in run_until_complete
self.run_forever()
File "/home/felix/miniconda3/envs/bliss/lib/python3.9/asyncio/base_events.py", line 601, in run_forever
self._run_once()
File "/home/felix/miniconda3/envs/bliss/lib/python3.9/asyncio/base_events.py", line 1869, in _run_once
event_list = self._selector.select(timeout)
File "/home/felix/miniconda3/envs/bliss/lib/python3.9/site-packages/gevent/selectors.py", line 201, in select
self._ready.wait(timeout)
File "src/gevent/event.py", line 163, in gevent._gevent_cevent.Event.wait
File "src/gevent/_abstract_linkable.py", line 521, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait
File "src/gevent/_abstract_linkable.py", line 487, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
File "src/gevent/_abstract_linkable.py", line 490, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
File "src/gevent/_abstract_linkable.py", line 442, in gevent._gevent_c_abstract_linkable.AbstractLinkable._AbstractLinkable__wait_to_be_notified
File "src/gevent/_abstract_linkable.py", line 451, in gevent._gevent_c_abstract_linkable.AbstractLinkable._switch_to_hub
File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
File "/home/felix/projects/bliss/bliss/common/greenlet_utils/asyncio_gevent.py", line 171, in wrap_func
result = orig_func(*args, **kw)
File "/home/felix/projects/bliss/bliss/shell/cli/repl.py", line 670, in eval
raise KeyboardInterrupt
KeyboardInterrupt
Edited by Lucas Felix

Merge request reports