Thread termination

Stefan Schukat SSchukat at dspace.de
Fri Oct 13 12:51:25 CEST 2006


Reading from your last posts you are using COM objects. Therefore you
should not "kill" the thread since this
would lead to reference leaks. So there are only two ways left:

1. Program a specific interpreter and not use python.exe which
implements an access to PyThreadState_SetAsyncExc
2. Check in the separate thread at specific times a variable which is
set in the main thread.

Both need the try finally construct in the threadfunction to release COM
objects in the right way.
I.e., (taking the source from Roger):


def ThreadFunction(istream, dest):
      pythoncom.CoInitialize() // Initialize COM Runtime for this thread
	try:
		d=pythoncom.CoGetInterfaceAndReleaseStream(istream,
pythoncom.IID_IDispatch)
	     	my_ie=win32com.client.Dispatch(d)
	     	my_ie.Navigate(dest)
	finally:
		my_ie = None  // Release COM object
 	      pythoncom.CoUninitialize() // Release COM Runtime for this
thread


	Stefan



More information about the Python-list mailing list