1

I have a problem trying to send stdout in realtime to a log file with nohup by the command

nohup python3 -u {} --model_dir={} --pipeline_config_path={} --num_train_steps={} > /lab/FastAPI/logs/train.out &

I'm using os.system() function to execute it directly from the code. I read many articles which suggests to export a variable to flush the stdout. It worked when I try to copy the generated command and executing it in the terminal, but from code it doesn't work.

train_command = "nohup python3 -u {} --model_dir={} --pipeline_config_path={} --num_train_steps={} > /lab/FastAPI/logs/train.out &".format(self.TRAINING_SCRIPT, self.paths['CHECKPOINT_PATH'], self.files['PIPELINE_CONFIG'], self.num_steps)
os.environ["PYTHONUNBUFFERED"] = "1"
os.system(train_command)

The output file is created on the execution, but is empty. Even if the process is done, still empty.

Conclusion: If I copy the command and execute it on the terminal, it works fine, when I'm executing the same command with os.system(), the output file is generated but remains empty.

Could you help me with this situation?

0 Answers0