A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/329994.html below:

Python and file locking - NFS or MySQL?

Python and file locking - NFS or MySQL? Python and file locking - NFS or MySQL?Fredrik Lundh fredrik at pythonware.com
Fri Sep 2 09:11:33 EDT 2005
Fredrik Lundh wrote:

> 5) check the number of links to each file
>
>       n = os.stat(tempfile)[3]
>       m = os.stat(lockfile)[3]

aw, forget that.  I shouldn't trust google over my own code.  here's the
correct algorithm:

    f = open(tempfile, "w")
    f.close()

    n = os.stat(tempfile)[3]
    os.link(tempfile, lockfile)
    m = os.stat(tempfile)[3]
    if n == m+1:
        success!

where n==1 and m==2.  the os.link call can be placed in a try/except
clause (if it fails, m won't be 2), or you can use a try/except around the
entire thing.

</F> 




More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4