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


Groups > comp.lang.python > #65770

Re: system wide mutex

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: system wide mutex
Date 2014-02-09 18:14 +0200
Organization A noiseless patient Spider
Message-ID <87ob2ggt57.fsf@elektro.pacujo.net> (permalink)
References <cf62da1e-45f0-4ace-924a-b3035063c71e@googlegroups.com>

Show all headers | View raw


Asaf Las <roegltd@gmail.com>:

> Which one is most recommended to use for mutex alike locking to 
> achieve atomic access to single resource:
>
> - fcntl.lockf

I recommend fcntl.flock:

========================================================================
#!/usr/bin/python3

import sys, fcntl, time

with open("test.lock", "w+") as lock:
    fcntl.flock(lock.fileno(), fcntl.LOCK_EX)
    # begin critical
    sys.stdout.write("hello\n")
    time.sleep(3)
    sys.stdout.write("world\n")
    # end critical
========================================================================


Marko

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


Thread

system wide mutex Asaf Las <roegltd@gmail.com> - 2014-02-09 02:39 -0800
  Re: system wide mutex Asaf Las <roegltd@gmail.com> - 2014-02-09 03:00 -0800
  Re: system wide mutex Skip Montanaro <skip@pobox.com> - 2014-02-09 05:00 -0600
    Re: system wide mutex Asaf Las <roegltd@gmail.com> - 2014-02-09 03:07 -0800
    Re: system wide mutex Roy Smith <roy@panix.com> - 2014-02-09 09:45 -0500
      Re: system wide mutex Skip Montanaro <skip@pobox.com> - 2014-02-09 09:40 -0600
      Re: system wide mutex Chris Angelico <rosuav@gmail.com> - 2014-02-10 09:09 +1100
  Re: system wide mutex Marko Rauhamaa <marko@pacujo.net> - 2014-02-09 18:14 +0200
    Re: system wide mutex Asaf Las <roegltd@gmail.com> - 2014-02-09 09:39 -0800
  Re: system wide mutex Grant Edwards <invalid@invalid.invalid> - 2014-02-10 17:00 +0000
  Re: system wide mutex Miki Tebeka <miki.tebeka@gmail.com> - 2014-02-10 09:46 -0800

csiph-web