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


Groups > comp.lang.python > #40001

Re: Writing to same file from two threads

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!not-for-mail
From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.lang.python
Subject Re: Writing to same file from two threads
Date 26 Feb 2013 20:08:05 GMT
Organization Freie Universitaet Berlin
Lines 21
Message-ID <ap4j15Fmb9lU1@mid.uni-berlin.de> (permalink)
References <ap420lFiectU1@mid.uni-berlin.de> <7xliabvv4g.fsf@ruckus.brouhaha.com>
X-Trace news.uni-berlin.de X6lYoEI+aHB/L0ou2l0IOgKR1jHU6VU0Utto+grVly9gmL
X-Orig-Path not-for-mail
User-Agent tin/1.9.3-20080506 ("Dalintober") (UNIX) (Linux/2.6.30-1-amd64 (x86_64))
Xref csiph.com comp.lang.python:40001

Show key headers only | View raw


Paul Rubin <no.email@nospam.invalid> wrote:
> jt@toerring.de (Jens Thoms Toerring) writes:
> > in garbled output (i.e. having some output from A inside a
> > line written by B or vice versae) because the "main thread" or

> Yes they do get garbled like that.  Preferred Python style is put a
> single thread in charge of all the i/o to that file, and communicate
> with it by message passing through Queue objects.  That is safer than
> directly using locks.

Thank you for confirmig my suspicion;-) But you have induced
another question: why is using a Queue safer than locking (not
that I doubt that it might be more elegant etc.). Is it "safer"
because it's less likely that one gets it wrong (e.g. by for-
grtting to acquire the lock) or is there something inherently
unsafe about locks?

                  Thank you and best regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

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


Thread

Writing to same file from two threads jt@toerring.de (Jens Thoms Toerring) - 2013-02-26 15:17 +0000
  Re: Writing to same file from two threads Paul Rubin <no.email@nospam.invalid> - 2013-02-26 09:32 -0800
    Re: Writing to same file from two threads jt@toerring.de (Jens Thoms Toerring) - 2013-02-26 20:08 +0000
      Re: Writing to same file from two threads Antoine Pitrou <solipsis@pitrou.net> - 2013-02-27 13:26 +0000
        Re: Writing to same file from two threads jt@toerring.de (Jens Thoms Toerring) - 2013-02-27 16:05 +0000
        Re: Writing to same file from two threads Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-28 01:05 +0000
          Re: Writing to same file from two threads Antoine Pitrou <solipsis@pitrou.net> - 2013-03-01 14:54 +0000

csiph-web