Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #196400
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Best (simplest) way to share data between processes |
| Date | 2024-07-07 23:47 +0100 |
| Message-ID | <mailman.15.1720392424.2981.python-list@python.org> (permalink) |
| References | <9a8nlk-jb81.ln1@q957.zbmc.eu> <B4D7CB24-28E5-4CAC-AA42-5C47C3F6F470@barrys-emacs.org> <6e86fff1-d24c-42c9-bc72-7e22757686ec@mrabarnett.plus.com> |
On 2024-07-07 23:27, Barry via Python-list wrote: > > >> On 7 Jul 2024, at 22:13, Chris Green via Python-list <python-list@python.org> wrote: >> >> a simple file lock can then >> be used to prevent simultaneous access (well, simultaneous access when >> the writing process is writing). > > There is a simple pattern to make this robust. > > Write new values to a tmp file. > Close the tmp file. > Then use os.rename(tmpfile, productionfile). > > This is guaranteed that any process that reads the file will only see all the old file contents or all the new file contents, never a mix of both. > For clarity I'd recommend os.replace instead. This is because on Windows os.rename it would complain if the target file already exists, but os.replace has the same behaviour on both Linux and Windows.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Best (simplest) way to share data between processes Chris Green <cl@isbd.net> - 2024-07-06 08:28 +0100
Re: Best (simplest) way to share data between processes Gordinator <gordinator@gordinator.org> - 2024-07-06 20:03 +0100
Re: Best (simplest) way to share data between processes Piergiorgio Sartor <piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de> - 2024-07-06 21:32 +0200
Re: Best (simplest) way to share data between processes Chris Green <cl@isbd.net> - 2024-07-08 13:52 +0100
Re: Best (simplest) way to share data (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-07-07 01:43 +0000
Re: Best (simplest) way to share data (Posting On Python-List Prohibited) Chris Green <cl@isbd.net> - 2024-07-08 13:56 +0100
Re: Best (simplest) way to share data (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-07-09 05:52 +0000
Re: Best (simplest) way to share data Chris Green <cl@isbd.net> - 2024-07-09 11:02 +0100
Re: Best (simplest) way to share data between processes Barry <barry@barrys-emacs.org> - 2024-07-07 23:27 +0100
Re: Best (simplest) way to share data between processes MRAB <python@mrabarnett.plus.com> - 2024-07-07 23:47 +0100
Re: Best (simplest) way to share data between processes Barry Scott <barry@barrys-emacs.org> - 2024-07-08 09:34 +0100
Re: Best (simplest) way to share data between processes Left Right <olegsivokon@gmail.com> - 2024-07-07 23:55 +0200
csiph-web