Is print thread safe?

Chris Angelico rosuav at gmail.com
Tue Aug 12 09:53:03 EDT 2014


On Tue, Aug 12, 2014 at 2:31 PM, Cameron Simpson <cs at zip.com.au> wrote:
> I would expect file.write to be fast enough that the lock would usually be
> free.

Until the day when it becomes really REALLY slow, because your
program's piped into 'less' and the user's paging through it. But even
apart from that, writing to stdout can take a notable amount of time.
Expecting the lock to usually be free will depend on the nature of the
program - how much of it is spent in silent computation and how much
in production of output. If that ratio is sufficiently skewed, then
sure, the lock'll usually be free.

ChrisA



More information about the Python-list mailing list