RE: Thread termination
Hello you are using the module variable ie inside the Generic Function, but you have to use "d" since this is the Python object which is allowed to access the COM object in the separate thread. Stefan From: Tejovathi P [mailto:[EMAIL PROTECTED] Sent: Monday, October 16, 2006 9:47 AMTo: Stefan SchukatSubject: Re: Thread termination HI all, I have a problem in accesing COM objects in threads. To be precise, lets assume that I have a class GenericFunctions which is defined as follows: import win32com.client, pythoncom, thread ie=win32com.client.Dispatch('internetexplorer.application') ie.Visible=1 class GenericFunctions: def __init__(self): print "In Constructor of Generic Functions" def MyNavigate(self,dest): ie.Navigate(dest) Now there is another file Main.py which is defined as follows: import win32com.client, pythoncom, thread from GenericFunctions import *obj = GenericFunctions() class Mainclass: def __init__(self); print "In Constructor of Main class" def threadFunction(self,dest): pythoncom.CoInitialize() d=pythoncom.CoGetInterfaceAndReleaseStream(s, pythoncom.IID_IDispatch) my_ie=win32com.client.Dispatch(d) obj.func(dest) # this is gving an error. pythoncom.CoUninitialize() if __name__ == "__main__": s=pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,ie) thread.start_new_thread(self.nav, (s,'www.google.com ') Basically, I want to access object of GenericFunctions class inside threadFunction(). However I was able to execute my_ie.Navigate("google.com"). But that was not I wanted. I am not knowing where the error is Please let me know the solution ASAP... Teja.P On 10/13/06, Stefan Schukat [EMAIL PROTECTED] wrote: Reading from your last posts you are using COM objects. Therefore youshould 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 whichimplements an access to PyThreadState_SetAsyncExc2. 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 COMobjects 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 thisthread Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread termination
Teja [EMAIL PROTECTED]wrote: Hi all, Does any one know how to terminate or kill a thread that is started with start_new_thread() in the middle of its execution? Any pointers? Thanks in advance Teja. can't be done from outside without co operation of thread in question. google this newsgroup - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread termination
Hendrik van Rooyen [EMAIL PROTECTED] wrote: can't be done from outside without co operation of thread in question. google this newsgroup Hopefully google will discover also the thread where the above statement is proved to be false ;-) This might be a useful thing to search for... ctypes.pythonapi.PyThreadState_SetAsyncExc -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread termination
Nick Craig-Wood [EMAIL PROTECTED] wrote: Hendrik van Rooyen [EMAIL PROTECTED] wrote: can't be done from outside without co operation of thread in question. google this newsgroup Hopefully google will discover also the thread where the above statement is proved to be false ;-) This might be a useful thing to search for... ctypes.pythonapi.PyThreadState_SetAsyncExc Where were you when we needed you some week or two ago? I *could* argue that using ctypes is cheating - But I wont... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Thread termination
Hi all, Does any one know how to terminate or kill a thread that is started with start_new_thread() in the middle of its execution? Any pointers? Thanks in advance Teja. -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread termination
G'day,As far as my understanding pertains, the thread dies shortly after the function returns (ends). You can call return anywhere within the function and kill the thread in the middle of its execution.On 13 Oct 2006 02:38:28 -0700, Teja [EMAIL PROTECTED] wrote: Hi all,Does any one know how to terminate or kill a thread that is startedwith start_new_thread() in the middle of its execution?Any pointers?Thanks in advanceTeja.-- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Thread termination
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread termination
Teja schrieb: Hi all, Does any one know how to terminate or kill a thread that is started with start_new_thread() in the middle of its execution? Any pointers? This has been discussed a bazillion times in this NG. The short answer is: no. For the long answer: do some googling :) Diez -- http://mail.python.org/mailman/listinfo/python-list