Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fcntl substitute on Windows

I received a Python project (which happens to be a Django project, if that matters,) that uses the fcntl module from the standard library, which seems to be available only on Linux. When I try to run it on my Windows machine, it stops with an ImportError, because this module does not exist here.

Is there any way for me to make a small change in the program to make it work on Windows?

like image 535
Ram Rachum Avatar asked Sep 14 '09 15:09

Ram Rachum


People also ask

Is Fcntl a standard library?

No, unistd. h and fcntl. h , etc are not part of standard C.

What is Fcntl module in Python?

(Unix only) The fcntl module provides an interface to the ioctl and fcntl functions on Unix. They are used for “out of band” operations on file handles and I/O device handles. This includes things like reading extended attributes, controlling blocking, modifying terminal behavior, and so on.


2 Answers

The substitute of fcntl on windows are win32api calls. The usage is completely different. It is not some switch you can just flip.

In other words, porting a fcntl-heavy-user module to windows is not trivial. It requires you to analyze what exactly each fcntl call does and then find the equivalent win32api code, if any.

There's also the possibility that some code using fcntl has no windows equivalent, which would require you to change the module api and maybe the structure/paradigm of the program using the module you're porting.

If you provide more details about the fcntl calls people can find windows equivalents.

like image 110
nosklo Avatar answered Sep 24 '22 21:09

nosklo


The fcntl module is just used for locking the pinning file, so assuming you don't try multiple access, this can be an acceptable workaround. Place this module in your sys.path, and it should just work as the official fcntl module.

Try using this module (source) for development/testing purposes only in windows.

def fcntl(fd, op, arg=0):     return 0          def ioctl(fd, op, arg=0, mutable_flag=True):     if mutable_flag:         return 0     else:         return ""      def flock(fd, op):     return          def lockf(fd, operation, length=0, start=0, whence=0):     return 
like image 29
Muhammad Soliman Avatar answered Sep 25 '22 21:09

Muhammad Soliman