Code Bug Fix: question on disowning process from python executable in zsh

Original Source Link

I’m encountering some problems when trying to run a process
in background and disown it in zsh with the &! shortcut.

I’m no expert of either zsh, nor python,
so it might very well be that I’m missing something obvious here.

The executable is the following python program, call it test.py (I’m using python2.7.15):

#!/usr/bin/env python
from __future__ import print_function
import time

for idx in range(5):
  print(idx)
  time.sleep(2)

with open('test.txt','w') as ofile:
  ofile.write('done')

With some trial-and-error, I noticed the following:

  1. if I run ./test.py &! and then logout, the process does not complete successfully
    (I check this by looking at the presence and content of the file test.txt);
    it looks like it’s not getting disowned, and logging out causes it to stop;

  2. if I run ./test.py > test2.txt &!, and then logout,
    it does work as expected (again, based on the presence of the test.txt file);

  3. if I comment out the the second line (from __future__ ..), modify the print statement,
    run ./test.py &!, and then logout, it also works as expected.

What am I missing? And would there be a way to make 1. work, without resorting to 2. or 3.?

Tagged : /

Leave a Reply

Your email address will not be published. Required fields are marked *