Issue
I have a Python script like the following:
#!/usr/bin/env python
print("Start")
sql = get_sql_from_file(...)
# The following function takes a long time to run
execute_oracle_driver(sql)
print("Finished")
I execute it with:
(my-env) $ time nohup python script.py &
Then I check if there's any initial output, but nothing:
(my-env) $ cat nohup.out
(my-env) $
I would at least expect to see "Start" after no more than a few seconds. Even after waiting a few minutes, then killing it, I get no output. If possible, how can I fix this?
Solution
Output is buffered by default, so you would need to ensure that the output is flushed; otherwise, no output will be seen in nohup.out
until the end of the program. One way to do that is as follows:
print("Start", flush=True)
Answered By - Anthony Tuininga