Path: csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: Writing to same file from two threads Date: Tue, 26 Feb 2013 09:32:31 -0800 Organization: Nightsong/Fort GNOX Lines: 8 Message-ID: <7xliabvv4g.fsf@ruckus.brouhaha.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx05.eternal-september.org; posting-host="d94d289a4df6ae47ea4d4f8b2ae808e7"; logging-data="27473"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XkrLcQioDnMODDJhB1yzi" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:fXYswCpzjqudBnP4h0l6SE5BMZY= sha1:f1xtqk1s0HcQut1hgfU4ehBt5DA= Xref: csiph.com comp.lang.python:39977 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.