Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76082

Re: Is print thread safe?

Date 2014-08-12 07:53 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: Is print thread safe?
References <53e8ea27$0$29981$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.12868.1407795799.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12Aug2014 02:07, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
>INADA Naoki wrote:
>
>> On Python 3, print is thread safe.
>> But Python 2 has broken scenario:
>
>Is this documented somewhere?

In python/2.7.6/reference/simple_stmts.html#index-22, "print" is described in 
terms of a "write" for each object, and a "write" for the separators. There is 
no mention of locking.

On that basis, I would find the interleaving described normal and expected. And 
certainly not "broken".

Just use a lock! And rebind "print"! Or use the logging system!

Cheers,
Cameron Simpson <cs@zip.com.au>

Wow!  Yet another place that I've been quoted...
         - Andy Beals <bandy@cinnamon.com>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is print thread safe? Steven D'Aprano <steve@pearwood.info> - 2014-08-11 07:44 +0000
  Re: Is print thread safe? INADA Naoki <songofacandy@gmail.com> - 2014-08-11 19:19 +0900
    Re: Is print thread safe? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-12 02:07 +1000
      Re: Is print thread safe? Cameron Simpson <cs@zip.com.au> - 2014-08-12 07:53 +1000
        Re: Is print thread safe? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-12 09:56 +1000
          Re: Is print thread safe? Chris Angelico <rosuav@gmail.com> - 2014-08-12 10:14 +1000
          Re: Is print thread safe? Marko Rauhamaa <marko@pacujo.net> - 2014-08-12 08:01 +0300
            Re: Is print thread safe? Cameron Simpson <cs@zip.com.au> - 2014-08-12 16:15 +1000
          Re: Is print thread safe? Cameron Simpson <cs@zip.com.au> - 2014-08-12 14:31 +1000
          Re: Is print thread safe? Chris Angelico <rosuav@gmail.com> - 2014-08-12 23:53 +1000

csiph-web