[python-win32] Ref-count bug in win32file.GetQueuedCompletionStatus
Fred Gansevles
gansevle at ewi.utwente.nl
Wed Jun 1 11:02:25 CEST 2005
Hi,
I think I've found a ref-count bug in win32file.GetQueuedCompletionStatus
running "svcbug.py s" starts a correct server and "svcbug.py s b"
starts a buggy server.
running "svcbug.py c" starts a client
____________________________________________________________________________
# svcbug.py
import win32file, win32pipe, pywintypes
PIPE = r"\\.\pipe\Bug.Svc"
BUFSIZE = 512
class Iocp:
def __init__(self, object):
self.port = win32file.CreateIoCompletionPort(-1, 0, 0, 0)
win32file.CreateIoCompletionPort(object.handle, self.port, 1, 0)
def wait_buggy(self):
win32file.GetQueuedCompletionStatus(self.port, -1)
def wait_good(self):
# keep a reference to the overlapped object
self.result = win32file.GetQueuedCompletionStatus(self.port, -1)[3]
class PipeService:
def __init__(self):
self.handle = win32pipe.CreateNamedPipe(PIPE,
win32pipe.PIPE_ACCESS_DUPLEX|
win32file.FILE_FLAG_OVERLAPPED,
win32pipe.PIPE_TYPE_MESSAGE|
win32pipe.PIPE_READMODE_MESSAGE|
win32pipe.PIPE_WAIT,
1, BUFSIZE, BUFSIZE,
win32pipe.NMPWAIT_WAIT_FOREVER,
None)
self.overlapped = pywintypes.OVERLAPPED()
win32pipe.ConnectNamedPipe(self.handle, self.overlapped)
def serve(self):
data = win32file.ReadFile(self.handle, BUFSIZE)[1]
win32file.WriteFile(self.handle, data)
def __del__(self):
win32pipe.DisconnectNamedPipe(self.handle)
if __name__ == '__main__':
import sys
if 's' in sys.argv:
svc = PipeService()
iocp = Iocp(svc)
if 'bug' in sys.argv:
iocp.wait_buggy()
else:
iocp.wait_good()
print sys.getrefcount(svc.overlapped)
svc.serve()
elif 'c' in sys.argv:
print win32pipe.CallNamedPipe(PIPE, "Hello there", BUFSIZE, 0)
____________________________________________________________________________
Fred Gansevles <mailto:Fred.Gansevles at ewi.utwente.nl> Phone: +31 53 489 4613
Org.: Twente University, Fac. of EWI, Box 217, 7500 AE Enschede, Netherlands
"Linux is like a wigwam, No windows, no gates and an apache inside"
More information about the Python-win32
mailing list