| Deutsch English Français Italiano |
|
<sniolk-8t7.ln1@lazy.lzy> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Piergiorgio Sartor <piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de> Newsgroups: comp.lang.python Subject: Re: Best (simplest) way to share data between processes Date: Sat, 6 Jul 2024 21:32:44 +0200 Organization: A noiseless patient Spider Lines: 47 Message-ID: <sniolk-8t7.ln1@lazy.lzy> References: <9a8nlk-jb81.ln1@q957.zbmc.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 06 Jul 2024 21:33:57 +0200 (CEST) Injection-Info: dont-email.me; posting-host="7be1f0409d9be439c6bb3cc1b7bb2cf6"; logging-data="4144129"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yWVrZ2Bl18/iWwak7Qwtj" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:jDY31jpnCO1yiiV9ONLokfx1ioY= In-Reply-To: <9a8nlk-jb81.ln1@q957.zbmc.eu> Content-Language: it, en-GB Bytes: 2645 On 06/07/2024 09.28, Chris Green wrote: > I have a Raspberry Pi in my boat that uses I2C to read a number of > voltages and currents (using ADS1115 A2D) so I can monitor the battery > condition etc. > > At present various different scripts (i.e. processes) just read the > values using the I2C bus whenever they need to but I'm pretty sure > this (quite rarely) results in false readings because two processes > try to read at the same time. > > Thus I'm looking for ways to prevent simultaneous access. Why using "different scripts"? Is it there any particular reason? Maybe it would be better, if possible, to have a single script, which, sequentially, reads whatever needs to be read (or written). In a loop. This is even simpler than using a file. bye, pg > One fairly obvious way is to have single process/script which reads > the A2D values continuously and writes them to a file. All other > scripts then read from the file as needed, a simple file lock can then > be used to prevent simultaneous access (well, simultaneous access when > the writing process is writing). > > Is this the simplest approach? Are there better ways using > multiprocess? (They look more complicated though). > > The I2C bus itself has a mutex but I don't think this guarantees that > (for example) an A2D reading is atomic because one reading takes more > than one I2C bus access. > > Would a mutex of some sort around each I2C transaction (i.e. complete > A2D reading) be a better way to go? > -- piergiorgio