Python without a tty

Hans Mulder hansmu at xs4all.nl
Fri Sep 30 23:09:02 CEST 2011


On 30/09/11 20:34:37, RJB wrote:
> You could try the old UNIX "nohup ...&" technique for running a
> process in the background (the&) with no HangUP if you log out:
>
> $ nohup python -c "import sys,os; print
> os.isatty(sys.stdout.fileno())"&
> appending output to nohup.out
> $ cat nohup.out
> False
>
> But that is over kill I guess.
>
> One worrying detail.... the definition of a running process in
> UNIX implies is that it has standard input/output files open.
> You'd be wise to make sure that they are connected to things
> that are safe.... /dev/null.
>
> Even so /dev/tty can be opened any way...

Not if you really detach from your tty: after you've detached,
there is no tty for /dev/tty to connect to and any attempt to
open it will raise IOError.

-- HansM




More information about the Python-list mailing list