[Twisted-Python] fcntl

Moshe Zadka m at moshez.org
Sun Sep 23 08:54:39 EDT 2001


FCNTL exists in Python 2.2, but gives a DeprecationWarning. We should
all be greatful for this warning in advance of a backwards incompatibility
looming in the future.

Here is a patch to future-proof the code
I've checked it with 1.5.2 and 2.2a3

Please let me know of any objections

Index: twisted/internet/process.py
===================================================================
RCS file: /cvs/Twisted/twisted/internet/process.py,v
retrieving revision 1.6
diff -u -r1.6 process.py
--- twisted/internet/process.py	2001/08/18 09:31:01	1.6
+++ twisted/internet/process.py	2001/09/23 13:03:15
@@ -24,7 +24,10 @@
 if os.name == 'posix':
     # Inter-process communication and FCNTL fun isn't available on windows.
     import fcntl
-    import FCNTL
+    if (sys.hexversion >> 16) >= 0x202:
+        FCNTL = fcntl
+    else:
+        import FCNTL
 
 from twisted.persisted import styles
 from twisted.python import log, threadable
@@ -185,7 +188,7 @@
         for fd in stdout_write, stderr_write, stdin_read:
             os.close(fd)
         for fd in (stdout_read, stderr_read):
-            fcntl.fcntl(fd, FCNTL.F_SETFL, FCNTL.O_NONBLOCK)
+            fcntl.fcntl(fd, FCNTL.F_SETFL, os.O_NONBLOCK)
         self.stdout = os.fdopen(stdout_read, 'r')
         self.stderr = os.fdopen(stderr_read, 'r')
         self.stdin = stdin_write

-- 
The Official Moshe Zadka FAQ: http://moshez.geek
The Official Moshe Zadka FAQ For Dummies: http://moshez.org
Read the FAQ





More information about the Twisted-Python mailing list