Python script output on Job Log only displayed at the end of the script
search cancel

Python script output on Job Log only displayed at the end of the script

book

Article ID: 200639

calendar_today

Updated On:

Products

CA Automic Workload Automation - Automation Engine CA Automic Dollar Universe CA Automic Applications Manager (AM)

Issue/Introduction

When launching python scripts via a Jobs / Uproc / Interpreter, the python script output is not displayed on the Jobs Report / Uproc Job Log until the python script has finished its execution.

Environment

Any Scheduler / Environment using python scripts

Cause

Expected behavior, by default python buffers stdout and stderr streams until the end of the execution.

The option -u will allow to have the expected behavior:

-u     : force the stdout and stderr streams to be unbuffered;
         this option has no effect on stdin; also PYTHONUNBUFFERED=x

Resolution

In order to be able to have the Job Log / Report updated in real-time while the python script is running, you need to add the option -u Invoke the python script via python -u yourscript.py

For example, this is the example of UC_EXT_INTERPRETERS_WINDOWS set on client 0 for Automic Workload Automation:

Please note that python.exe folder location SHOULD be available on the Windows PATH variable.

The same for Unix/Linux on UC_EXT_INTERPRETERS_UNIX