python3 -i test.py
opens an interactive python shell after running test.py. However, if I try to run it in the background with python3 -i test.py &
the job stops automatically with a ^C
and shows
[4]+ Stopped python3 -i test.py
, and I can't access python's interactive shell (with the variables from test.py still in the environment) afterwards. fg
ing the process (i.e. fg %4
) leads to an interactive shell where my input can't be seen but is still run after pressing <Enter>
. How do I run the interactive shell "normally" after running test.py in the background?
(For reference, test.py contains
from time import sleep a = 'hello world' for i in range(10): sleep(1) print(a)
and my shell looks like this:
$ python3 -i test.py & [4] 6708 $ hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world fg %4 python3 -i test.py >>> 'hello world' >>>
and I typed a
after being prompted by the first >>>
, but it isn't shown. )
-- Edit @muru --
Sending it to the bg after running it normally in the fg gives:
$ $ $ python3 -i test.py hello world hello world hello world hello world ^Z [4]+ Stopped python3 -i test.py $ bg %4 [4]+ python3 -i test.py & $ hello world hello world hello world hello world hello world hello world echo 'hello world' hello world [4]+ Stopped python3 -i test.py $ $
where shell was expecting input and I typed echo 'hello world'
after the 10 "Hello World"'s.
bg
).