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


Groups > comp.lang.python > #50428

Re: Concurrent writes to the same file

From Nobody <nobody@nowhere.com>
Subject Re: Concurrent writes to the same file
Date 2013-07-11 09:30 +0100
Message-Id <pan.2013.07.11.08.30.35.284000@nowhere.com>
Newsgroups comp.lang.python
References <mailman.4565.1373518632.3114.python-list@python.org>
Organization Zen Internet

Show all headers | View raw


On Wed, 10 Jul 2013 22:57:09 -0600, Jason Friedman wrote:

> Other than using a database, what are my options for allowing two processes
> to edit the same file at the same time?  When I say same time, I can accept
> delays.

What do you mean by "edit"? Overwriting bytes and appending bytes are
simple enough, but inserting or deleting bytes such that subsequent bytes
change their offsets is harder.

> I considered lock files,

Well, you shouldn't have, unless you're targeting a platform which doesn't
support file locks (are there any left?).

> but I cannot conceive of how I avoid race conditions.

By using locks. E.g. fcntl.lockf() or msvcrt.locking().

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


Thread

Concurrent writes to the same file Jason Friedman <jsf80238@gmail.com> - 2013-07-10 22:57 -0600
  Re: Concurrent writes to the same file Nobody <nobody@nowhere.com> - 2013-07-11 09:30 +0100

csiph-web