joseph pareti
joseph pareti

Reputation: 97

nohup: ignoring input, but my python program DOES require input

train.py is a python program that parses the input variables using argparse, and should run in the background without an attached terminal, but invariably the input is ignored. I tested the following options:

/home/workspace# nohup /home/workspace/train.py vgg19 3000 1 cpu &

and

nohup /home/workspace/doit &

where doit is a script containing

/home/workspace/train.py vgg19 3000 1 cpu

which all result in:

home/workspace# nohup: ignoring input and appending output to 'nohup.out'

The only workaround that works (yet not acceptable for my project) is to hard-code the input variables in the python program and use :

nohup python -u ./train_LONG.py &

Moreover, which is super confusing, even the following command results in input being ignored:

nohup ./train_LONG.py -u &

Upvotes: 0

Views: 6021

Answers (3)

joseph pareti
joseph pareti

Reputation: 97

A solution that works for me is as follows:

  1. Build a script do_script
  2. submit the script nohup /home/workspace/do_script &

where do_script is

    #!/bin/bash 
    python -u /home/workspace/train.py vgg19  8000 15  cuda 

Step # 1 above was decisive; it was proposed for a different application with similar requirements. Moreover, at the beginning of this work I saw no output in the log file: this blog made be aware that the -u flag helps avoiding output buffering. As a result the application survives across workspace disconnects and collects all relevant outputs in the log file

Upvotes: 0

tripleee
tripleee

Reputation: 189357

You are mistaken about what the error message means. It relates to standard input, not command-line arguments.

For the record, to run a process which needs to read standard input with nohup, add a redirection.

nohup yourprogram <file &

or with a here document

nohup yourprogram <<\HERE &
first line of input
second line of input
etc
HERE

or with a pipe

nohup printf '%s\n' "first line of input" "second line of input" etc |
yourprogram &

Upvotes: 1

Jimmy Ding
Jimmy Ding

Reputation: 34

Nohup does not take input from stdin. The best option for passing in inputs while running within nohup is getting input through command line arguments using libraries like argparse. There are alternatives like using network for input or using other utilities like screen, but command-line arguments are generally easier to work with if you're working with applications that runs in the background.

Upvotes: 0

Related Questions