[Tutor] Releasing Memory ( In Reference to Window COM Objects )

Gooch, John John.Gooch at echostar.com
Mon Nov 8 18:39:49 CET 2004


I have a Python script that hits a few thousand systems a day. It runs about
60 threads at a time, each making a WMI connection to a system and then
getting some data for later insertion into a database. Every since I
starting running the script ( daily ), the Windows 2000 SP4 system  it runs
on will no longer allow access to Windows networking resources ( says "not
enough storage to process this request". The system is running and pingable,
but it will repeat that error it you try to access a network resource such
as a Windows file share or other network connection. 

I did notice I put the "CoInitialize()" command within a loop that ran for
each system the thread queried, while I have the "CoUninitialize()" command
running once at the end. I moved the "CoInitialize()" command out of the
loop so it only runs once now instead of several hundred/thousand times, but
I want to make sure I am releasing resources properly. 

One thing I am looking at is closing the WMI connection to a system before I
make a connection to another system. I can't seem to find a "close" command
for WMI, though. To help readers understand what my script is doing, here is
some psuedocode


"pythoncom.CoInitialize()"
while the hostname queue is not empty
	Get hostname from Queue Object
		ping the system
		if it is online, attempt to make a WMI connection 
			i.e. 	"wmi =
win32com.client.GetObject('winmgmts://'+hostname )"
			if connection is successful, query for some data and
put it back in another Queue object
"pythoncom.CoUninitialize()"

In vbscript, the wmi object is set to 'nothing' like so "Set wmi = Nothing",
which I guess releases the resources for that connection. Is there a way I
should be doing this in Python? Are there any other possible 'memory leaks'
that could be causing the issue detailed above? 

Your help is appreciated.

Thank You, 
 

 
John A. Gooch
Systems Administrator
IT - Tools
EchoStar Satellite L.L.C.
9601 S. Meridian Blvd.
Englewood, CO  80112
Desk: 720-514-5708 


More information about the Tutor mailing list