JrtPec
JrtPec

Reputation: 321

How to print to console in a Python WebJob on Microsoft Azure?

How do I print debug information from a Python script to the Azure WebJob Console?

I have successfully deployed a continuously running Python WebJob on Microsoft Azure, I have included my packages, and when the console showed some errors I've been able to fix them and re-upload through FTP.

Right now, the console (Azure WebJobs Dashboard) shows that my script is running.

[10/29/2015 10:42:53 > a19167: SYS INFO] Status changed to Starting [10/29/2015 10:42:53 > a19167: SYS INFO] Job directory change detected: Job file 'run.py' timestamp differs between source and working directories. [10/29/2015 10:42:58 > a19167: SYS INFO] Run script 'run.py' with script host - 'PythonScriptHost' [10/29/2015 10:42:58 > a19167: SYS INFO] Status changed to Running

However, my script is littered with print() statements which don't show. I have also tried sys.stdout.write() and sys.stderr.write() but they don't work either.

UPDATE: Print messages do show! They just appear in bulk, once every few hours...

Upvotes: 2

Views: 1484

Answers (1)

pedrusky
pedrusky

Reputation: 246

To immediately see your log statements in the Azure WebJobs Dashboard, simply call sys.stdout.flush()

Flushing the console output makes sense after intializing the web job, and after processing a single task (e.g. processing a queue message).

Upvotes: 3

Related Questions