command line - How can a Python program background itself? -
consider following python command-line program. doesn't work because incomplete, think illustrates problem:
#!/usr/bin/python3 import multiprocessing pool = multiprocessing.pool() task in expensive_iterator_with_user_interaction(): pool.call_async(expensive_computation, (task,)) pool.close() print("dear user, may press ctrl-z , bg script.") pool.join()
thus, problem scripts needs user input while it's launching expensive parallel processes. there moment when user interaction not needed anymore. then, ask user background process shell actions.
however, can achieved program itself?
(side note: core of problem entanglement of user input firing “expensive computations”. therefore, cannot separate both in 2 scripts, , letting 1 spawning other daemon.)
the command screen
may you.
use screen -l
create new session , run application. after inputting data, can press "ctrl-a" , press "d" on keyboard detach session.
now, application running in background.
if want other things or input more data, can use command screen -r
reattach previous session.
screen
virtual screen, can switch program background or foreground according needs.
Comments
Post a Comment