oi|dZddlZddlZddlZddlZddlZddlZdZdZ dZ dZ dZ dZ ed kre e ejd ejejdksejdkr,ed ejejfzdSed dSdS) aTesting pasing object between multiple COM threads Uses standard COM marshalling to pass objects between threads. Even though Python generally seems to work when you just pass COM objects between threads, it shouldn't. This shows the "correct" way to do it. It shows that although we create new threads to use the Python.Interpreter, COM marshalls back all calls to that object to the main Python thread, which must be running a message loop (as this sample does). When this test is run in "free threaded" mode (at this stage, you must manually mark the COM objects as "ThreadingModel=Free", or run from a service which has marked itself as free-threaded), then no marshalling is done, and the Python.Interpreter object start doing the "expected" thing - ie, it reports being on the same thread as its caller! Python.exe needs a good way to mark itself as FreeThreaded - at the moment this is a pain in the but! Nc |ddks Jd |dtd#tj$r*}ddl}|d|jks JdYd}~dSd}~wwxYw)Nz1+1z*The interpreter returned the wrong result.z*The interpreter did not raise an exceptionrz?The interpreter exception was not winerror.DISP_E_TYPEMISMATCH.)EvalAssertionError pythoncom com_errorwinerrorDISP_E_TYPEMISMATCH)interpdetailsr s EC:\PYTHON\Scheduler\python\Lib\site-packages\win32com/test/testGIT.py TestInterpr s ;;u   " " "$P " " "  EIJJJ     qzX9999 M:99999999 s$A BA==Bc t|tj|dS#tj|wxYwN)DoTestInterpInThread win32eventSetEvent) stopEventcookies r TestInterpInThreadr-sC'V$$$I&&&&& I&&&&s'=cltjtjdtjtjSr)rCoCreateInstanceCLSID_StdGlobalInterfaceTable CLSCTX_INPROCIID_IGlobalInterfaceTabler CreateGITr4s,  %/ +   rc tjtj}t }||tj}tj |}t|| dtd|| dfzd}tjdS#tjYdSxYw)Nzimport win32apiz>The test thread id is %d, Python.Interpreter's thread ID is %dzwin32api.GetCurrentThreadId())r CoInitializewin32apiGetCurrentThreadIdrGetInterfaceFromGlobal IID_IDispatchwin32comclientDispatchrExecprintrCoUninitialize traceback print_exc)rmyThreadGITr s r rr=s   .00kk++FI4KLL))&116 %&&& L%DEEF G    """""s CCC/cg}t|D]J}tjdddd}tjt ||f||K|S)zCreates multiple threads using simple (but slower) marshalling. Single interpreter object, but a new stream is created per thread. Returns the handles the threads will set when complete. Nr)ranger CreateEvent_thread start_newrappend) numThreadsrretihEvents r BeginThreadsSimpleMarshalr9Rsi C :  'aD99,vv.>??? 6 Jrc tdtjzt}tjd}||jtj }|d|}d} tj |ddtj }|tjkr:|tjt|zkr|dz }|t|krn}nj|tjt|zkrtjn6tdtjtjfzn#t&$rYnwxYw||~~dS)NzThe main thread is %dzPython.Interpreterriz:Waiting for thread to stop with interfaces=%d, gateways=%d)r)r!r"rr%r&r'RegisterInterfaceInGlobal_oleobj_rr$rMsgWaitForMultipleObjects QS_ALLINPUT WAIT_OBJECT_0lenPumpWaitingMessages_GetInterfaceCount_GetGatewayCountKeyboardInterruptRevokeInterfaceFromGlobal)fnr.r revents numFinishedrcs r testrLas !X%@%B%B CDDD ++C _ % %&: ; ;F  * *6?IrRs|,    '''*      D zD "###HN3I#y#%%**.Hi.H.J.Ja.O.O  2+y+--/Iy/I/K/KL M     gr