Codes from my life

Today I encountered a weird problem while running a python script with nohup. I was not getting anything in the output file even after waiting for 2-3 minutes which was unusual as I have used nohup on countless occasions with bash scripts and had not seen this issue.

Python itself buffers stdout and stderr which was causing this issue. So you have to explicitly disable buffering when you execute python scripts with nohup.

$nohup python -u script.py

With -u parameter python will disable the buffering and you will get all the outputs as it happens.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: