Python Forum

Full Version: Screen printing on different threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi folks.

In a multi threaded app, how can I assure one 'print' command completes with a carriage return before another thread butts in and prints data on the same line?

I have a central report def which I use to format and print data in the main file, but there are other files/scripts that are called on new threads.

Do I need a reporting script that all other modules/files/scripts use?

Thanks.
Quote:I have a central report def which I use to format and print data in the main file, but there are other files/scripts that are called on new threads.

Since all your threads are writing to the same file; you may need locking mechanism to serialise the process. I would open the file once, and hold on to the file handler in a global variable, and use thread locks to access the file handler.

Does that makes sense?