[Stackless-checkins] r52324 - stackless/sandbox/libraries/slpmonkeypatch/resources/iocp.py

richard.tew python-checkins at python.org
Fri Oct 13 17:44:45 CEST 2006


Author: richard.tew
Date: Fri Oct 13 17:44:44 2006
New Revision: 52324

Modified:
   stackless/sandbox/libraries/slpmonkeypatch/resources/iocp.py
Log:
Updated Stackless replacement file object.  Now supports reading in a limited fashion.

Turns out my code was working but because I was indexing information about OVERLAPPED structures by id, my code worked in unexpected ways because the python object wrapper for OVERLAPPED structures is apparently created on demand (if you have a pointer to a structure, it will return a different instance each time).

Modified: stackless/sandbox/libraries/slpmonkeypatch/resources/iocp.py
==============================================================================
--- stackless/sandbox/libraries/slpmonkeypatch/resources/iocp.py	(original)
+++ stackless/sandbox/libraries/slpmonkeypatch/resources/iocp.py	Fri Oct 13 17:44:44 2006
@@ -2,17 +2,13 @@
 # but only on Stackless channels rather than blocking the whole
 # interpreter.. etc
 
-# BUG: At the moment there is a major problem.  Where the OVERLAPPED
-#      structure returned by GetQueuedCompletionState is not the same
-#      instance I am waiting for. In fact, I have no idea what it is
-#      or where it came from.
+# This gives a working file object for the purpose of reading, but
+# requires a lot more work, including some form of locking.
 
 import stackless
 from ctypes import windll, pythonapi
 from ctypes import c_int, c_long, c_ulong, c_void_p, byref, c_char_p, Structure, Union, py_object, POINTER, pointer
 from ctypes.wintypes import HANDLE, ULONG, DWORD, BOOL, LPCSTR, LPCWSTR, WinError
-import msvcrt
-import sys
 import os
 
 # Check os.name is "nt" ?
@@ -144,24 +140,19 @@
                     raise WinError()
 
             ov = ovp.contents
-            c = self.ForgetOverlappedReference(ov)
-            if c:
-                c.send(None)
-            else:
-                print "got bs channel in poll", ov
-
-    def HoldOverlappedReference(self, ov, c):
-        print id(self), "HoldOverlappedReference", ov, c
-        self.overlappedByID[id(ov)] = ov, c
-
-    def ForgetOverlappedReference(self, ov):
-        ovID = id(ov)
-        if self.overlappedByID.has_key(ovID):
-            c = self.overlappedByID[ovID][1]
-            del self.overlappedByID[ovID]
-            print id(self), "ForgetOverlappedReference", ov, c
-            return c
-        print id(self), "ForgetOverlappedReference", ov, "no entry!"
+            c = ov.channel
+            if not c:
+                raise RuntimeError("Something went horribly wrong in IOCP land")
+            self.UnregisterChannelObject(c)
+            c.send(None)
+
+    def RegisterChannelObject(self, ob, c):
+        self.overlappedByID[id(c)] = ob, c
+
+    def UnregisterChannelObject(self, c):
+        k = id(c)
+        if self.overlappedByID.has_key(k):
+            del self.overlappedByID[k]
 
 
 # ----------------------------------------------------------------------------
@@ -258,10 +249,8 @@
         if ret == 0:
             if windll.kernel32.GetLastError() != ERROR_IO_PENDING:
                 raise WinError()
-            iocpMgr.HoldOverlappedReference(ov, c)
-            print "blocking pre"
+            iocpMgr.RegisterChannelObject(self, c)
             c.receive()
-            print "blocking post"
 
         return str(readBuffer)
 
@@ -284,6 +273,7 @@
 def Test(s):
     s = r"C:\Richard\Programs\\"+ s
     f = FileObject(s, "rb")
+    f.seek(100)
     v = f.read()
     f.close()
     print len(v)

_______________________________________________
Stackless-checkins mailing list
Stackless-checkins at stackless.com
http://www.stackless.com/mailman/listinfo/stackless-checkins



More information about the Stackless-checkins mailing list