[Python-bugs-list] [ python-Bugs-617870 ] fcntl.flock() doesn't work in solaris

noreply@sourceforge.net noreply@sourceforge.net
Thu, 03 Oct 2002 01:36:49 -0700


Bugs item #617870, was opened at 2002-10-03 04:06
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=617870&group_id=5470

Category: Python Library
Group: Platform-specific
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: João Prado Maia (jcpm)
Assigned to: Nobody/Anonymous (nobody)
Summary: fcntl.flock() doesn't work in solaris

Initial Comment:
When trying the script below on Solaris:

# test_flock.py
import fcntl

def lock(fd, flags):
    fcntl.flock(fd.fileno(), flags)

def unlock(fd):
    fcntl.flock(fd.fileno(), fcntl.LOCK_UN)

fd = open('test.txt', 'w')
lock(fd, fcntl.LOCK_SH)
fd.write('testing')
unlock(fd)
fd.close()
# end of test_flock.py

$ uname -a
SunOS mercury 5.8 Generic_108529-13 i86pc i386 i86pc

I get the following output:

$ python test_flock.py
Traceback (most recent call last):
  File "test_flock.py", line 10, in ?
    lock(fd, fcntl.LOCK_SH)
  File "test_flock.py", line 4, in lock
    fcntl.flock(fd.fileno(), flags)
IOError: [Errno 9] Bad file number

This is the python version information:

$ python -V
Python 2.2.1

However, when I try the same script under Linux it works 
correctly (i.e. it creates the 'test.txt' file)

$ uname -a
Linux domain.com 2.4.9-31 #1 Tue Feb 26 07:11:02 
EST 2002 i686 unknown

Please let me know if you need any more information.

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-10-03 10:36

Message:
Logged In: YES 
user_id=21627

This is not a bug in Python, but a feature of your system.
>From flock(3UCB):

     Read permission is required on a file  to  obtain  a 
shared
     lock,   and  write  permission  is  required  to 
obtain  an
     exclusive lock.

Since you haven't opened the file for reading, you can not
obtain a shared lock - you need an exclusive lock for writing.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=617870&group_id=5470