Lockfile hanling

Ian Kelly ian.g.kelly at gmail.com
Tue Mar 31 15:17:10 EDT 2015


On Tue, Mar 31, 2015 at 12:58 PM, Christian Gollwitzer <auriocus at gmx.de> wrote:
> Am 31.03.15 um 16:50 schrieb Ervin Hegedüs:
>>
>> there is an app, written in Python, which stores few bytes of
>> datas in a single file. The application uses threads. Every
>> thread can modify the file, but only one at a time. I'm using a
>> lock file to prevent the multiple access.
>>
>> Here is the lock method:
>>
>> [...]
>> This works as well for me - about 3-4 weeks. After some weeks, I
>> got this error:
>>
>> OSError: [Errno 24] Too many open files: '/var/spool/myapp/queue.lock'
>>
>
> Can you try if fcntl.flock() does what you want? Should be better than
> inventing your own locking mechanism.

flock locks are per-process; they won't help for synchronizing access
between competing threads in the same process.



More information about the Python-list mailing list