win32: GetQueuedCompletionStatus problems?

dmost at magna.com.au dmost at magna.com.au
Sun Sep 10 17:34:00 EDT 2000


Im playing with the win32 extensions, in particular the use of IO
completion ports.

I seem to be able to get everything up and working, except that Im also
seeing something I dont understand.

win32file.GetQueuedCompletionStatus returns a tuple of the form (result,
nbytes, completionkey, overlapped)

In C, the overlapped object returned by GetQueuedCompletionStatus is the
same one as was handed to the overlapped opreation, which in this case
is win32file.WSARecv
In win32 python, the OVERLAPPED object returned by
win32file.GetQueuedCompletionStatus is a different one from that handed
to win32file.WSARecv.
>From the looks of things, win32file.GetQueuedCompletionStatus creates
new OVERLAPPED objects each time it returns.

Now, the OVERLAPPED class supports the ataching of an arbritary python
object to the OVERLAPPED instance, and it looks like
win32file.GetQueuedCompletionStatus should be transfering these
arbritray objects to the new OVERLAPPED object that it returns.

What I am seeing is that this happens once or twice and then starts
going awry.
For my testing, the object Im attaching to my OVERLAPPED object is a
simple string.
I get a string back once or twice and then I get this:
repr(object) --> <refcnt 4294967295 at 7c92b0>
The type of this is <type 'string'>, which is good, but a refcount of
4294967295 which decreases by one for each iteration makes me nervous of
memory leaks.

Any clues anyone?

---------------------------iocptest.py --------------------------------
import win32file, win32event
import pywintypes
import socket, time

overlapped = pywintypes.OVERLAPPED()
overlapped.object = "this is overlapped 1"
print overlapped

iocp = win32file.CreateIoCompletionPort(win32file.INVALID_HANDLE_VALUE,
None, 0, 1)

sListening = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sListening.setblocking(0)
sListening.bind('localhost', 4045)
sListening.listen(1)

sAccepting = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sAccepting.setblocking(0)
buf = win32file.AllocateReadBuffer(64)
win32file.AcceptEx( sListening , sAccepting , buf , overlapped )

iocp = win32file.CreateIoCompletionPort(sListening.fileno(), iocp, 0, 1)
rc = 0
print 'listen loop'
while rc != 1:
    (rc, nbytes, key, ol) = win32file.GetQueuedCompletionStatus( iocp,
1000 )
    print 'GetQueuedCompletionStatus --> ', rc, nbytes, key, ol
print 'GetAcceptExSockaddrs --> ', win32file.GetAcceptExSockaddrs(
sAccepting, buf )

overlapped2 = pywintypes.OVERLAPPED()
overlapped2.object = "this is overlapped 2"
print overlapped2

buf = win32file.AllocateReadBuffer(512)
iocp = win32file.CreateIoCompletionPort(sAccepting.fileno(), iocp, 0, 1)
print 'WSARecv --> ', win32file.WSARecv( sAccepting, buf, overlapped2)
data = ''
while 1:
    (rc, nbytes, key, ol) = win32file.GetQueuedCompletionStatus( iocp,
2000 )
    print 'GetQueuedCompletionStatus --> ', rc, nbytes, key,
ol, 'object:',
getattr(ol, 'object', None)
    if (rc == 1):
        data = data + buf[:nbytes]
        print 'data = ', data
        print 'WSARecv --> ', win32file.WSARecv( sAccepting, buf,
overlapped2)
        time.sleep(1)


-------------------------------- output from
iocptest.py ---------------------------------------------

<PyOVERLAPPED object at 7fb5d0>
listen loop
GetQueuedCompletionStatus -->  258 0 0 None
GetQueuedCompletionStatus -->  258 0 0 None
GetQueuedCompletionStatus -->  258 0 0 None
GetQueuedCompletionStatus -->  258 0 0 None
GetQueuedCompletionStatus -->  258 0 0 None
GetQueuedCompletionStatus -->  1 1 0 <PyOVERLAPPED object at 7fb7f0>
GetAcceptExSockaddrs -->  (2, ('127.0.0.1', 4045), ('127.0.0.1', 1387))
<PyOVERLAPPED object at 7fbc30>
WSARecv -->  (997, 0)
GetQueuedCompletionStatus -->  1 1 0 <PyOVERLAPPED object at 7fbde0>
with
object: this is overlapped 2
data =  s
WSARecv -->  (997, 0)
GetQueuedCompletionStatus -->  1 1 0 <PyOVERLAPPED object at 7fb640>
with
object: this is overlapped 2
data =  sd
WSARecv -->  (997, 0)
GetQueuedCompletionStatus -->  1 1 0 <PyOVERLAPPED object at 7fbbd0>
with
object: this is overlapped 2
data =  sda
WSARecv -->  (997, 0)
GetQueuedCompletionStatus -->  1 1 0 <PyOVERLAPPED object at 7fbec0>
with
object: <refcnt 0 at 7c92b0>
data =  sdas
WSARecv -->  (0, 6)
GetQueuedCompletionStatus -->  1 6 0 <PyOVERLAPPED object at 7fb7f0>
with
object: <refcnt 4294967295 at 7c92b0>
data =  sdasdasdas
WSARecv -->  (0, 7)
GetQueuedCompletionStatus -->  1 7 0 <PyOVERLAPPED object at 7fbd20>
with
object: <refcnt 4294967294 at 7c92b0>
data =  sdasdasdasdasdasd
WSARecv -->  (997, 0)
GetQueuedCompletionStatus -->  258 0 0 None object: None
GetQueuedCompletionStatus -->  1 1 0 <PyOVERLAPPED object at 7fb830>
with
object: <refcnt 4294967293 at 7c92b0>
data =  sdasdasdasdasdasda
WSARecv -->  (997, 0)
GetQueuedCompletionStatus -->  1 1 0 <PyOVERLAPPED object at 7fbd40>
with
object: <refcnt 4294967292 at 7c92b0>
data =  sdasdasdasdasdasdad
WSARecv -->  (0, 3)
GetQueuedCompletionStatus -->  1 3 0 <PyOVERLAPPED object at 7fb560>
with
object: <refcnt 4294967291 at 7c92b0>
data =  sdasdasdasdasdasdadasd



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list