Necesita vaciar stdout
después de imprimir:sys.stdout.flush()
; de lo contrario, llevará un tiempo llenar el búfer de salida estándar.
Pase a python el indicador -u para quitar el búfer de stdout
nohup python -u test.py &
Python almacenará en búfer stdout de lo contrario. Esto no requiere un cambio de código.
Desde la página del manual:
-u Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, stdout
and stderr in binary mode. Note that there is internal buffering in xreadlines(), readlines() and file-object
iterators ("for line in sys.stdin") which is not influenced by this option. To work around this, you will want
to use "sys.stdin.readline()" inside a "while 1:" loop.
Acabo de tener un problema similar. Mi guión funcionó bien sin nohup. Con nohup, el script fallaría con un SyntaxError.
El problema era el contexto de ejecución de nohup que usaría un alias de python
asignado a python2
en lugar de python3
.
Se corrigió especificando python3
en lugar de python
.