Python + Ubuntu Linux + nohup error: [1]+ Exit Python + Ubuntu Linux + nohup error: [1]+ Exit linux linux

Python + Ubuntu Linux + nohup error: [1]+ Exit


I usually face this in three cases:

  1. When an exception in the while loop occurs.

  2. When somewhere in the code I have pdb.set_trace() which is a debugging breakpoint.

  3. When somewhere in the code, input from user is requested as in raw_input("Please enter something: ")

Check your code to exclude these three causes.

Don't worry about the first message, it is just informing you that nohup is in work.

EDIT

  1. Before running the script with nohup make sure that the script itself works fine (This would actually be the first thing to try).


I suggest that you'd better use double fork magic to run your long-running program as a daemon instead of nohup. It is easy to debug and your program doesn't need external tools like nohup.

daemon.py

import sysimport os# double fork magicdef daemonize():    os.umask(0)    try:        pid = os.fork()    except OSError:        sys.exit(0)    if pid > 0:        sys.exit(0)    os.setsid()    try:        pid = os.fork()    except OSError:        sys.exit(0)    if pid > 0:        os._exit(0)    os.chdir('/')    import resource     # Resource usage information.    maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]    if (maxfd == resource.RLIM_INFINITY):        maxfd = 1024    # Iterate through and close all file descriptors.    for fd in range(0, maxfd):        try:            os.close(fd)        except OSError:   # ERROR, fd wasn't open to begin with (ignored)            pass    fd = os.open(os.devnull, os.O_RDWR)    os.dup2(fd, sys.stdin.fileno())    os.dup2(fd, sys.stdout.fileno())    os.dup2(fd, sys.stderr.fileno())

test.py

from daemon import daemonizeimport timedef test():    while True:        time.sleep(10)if __name__ == '__main__':    daemonize() # you could comment this line before you make sure your program run as you expect    test()

Now, using python test.py to make it run as a daemon and you could use ps aux | grep test.py to check it.


I agree with Ash, you're facing some trouble within your script.

I've tested your scenario and I assure you nohup isn't the problem:

Python code

$ cat practice_one.pywhile True:   print 'ok'

Nohup execution

m.ortiz.montealegre@CPX-XYR3G1DTHBU ~/python_excercises/nohup-python$ nohup python practice_one.py &[1] 10552m.ortiz.montealegre@CPX-XYR3G1DTHBU ~/python_excercises/nohup-python$ nohup: ignoring input and appending output to 'nohup.out'm.ortiz.montealegre@CPX-XYR3G1DTHBU ~/python_excercises/nohup-python$ ps      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND    10552   15248   10552       9992  cons1    6758389 16:52:27 /usr/bin/python2.7

So, try simplifying your script operations to find out which one is the problem by commenting the code and test until you find the culprit.