
    	h                     |   S r SSKrSSKrSSKrSSKrSSKrSSKrS rS r	S r
S rS rS r\S	:X  a  \" \5        \R                  " S
5        \R                   " 5         \R"                  " 5       S:w  d  \R$                  " 5       S:w  a,  \" S\R"                  " 5       \R$                  " 5       4-  5        g\" S5        gg)a  Testing 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                     U R                  S5      S:X  d   S5       e U R                  S5        [        S5      e! [        R                   a(  nSS KnUS   UR
                  :X  d   S5       e S nAg S nAff = f)Nz1+1   z*The interpreter returned the wrong result.z*The interpreter did not raise an exceptionr   z?The interpreter exception was not winerror.DISP_E_TYPEMISMATCH.)EvalAssertionError	pythoncom	com_errorwinerrorDISP_E_TYPEMISMATCH)interpdetailsr	   s      hC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\win32com/test/testGIT.py
TestInterpr       sw    ;;u"P$PP"
EIJJ 
qzX999 	
M	
9
s   : A6A11A6c                 ~     [        U5        [        R                  " U 5        g ! [        R                  " U 5        f = fN)DoTestInterpInThread
win32eventSetEvent)	stopEventcookies     r   TestInterpInThreadr   -   s,    'V$I&
I&s   $ <c                      [         R                  " [         R                  S [         R                  [         R                  5      $ r   )r   CoCreateInstanceCLSID_StdGlobalInterfaceTableCLSCTX_INPROCIID_IGlobalInterfaceTable     r   	CreateGITr   4   s3    %%//++	 r   c                     [         R                  " 5         [        R                  " 5       n[	        5       nUR                  U [         R                  5      n[        R                  R                  U5      n[        U5        UR                  S5        [        SXR                  S5      4-  5        S n[         R                  " 5         g !   [        R                   " 5          g = f)Nzimport win32apiz>The test thread id is %d, Python.Interpreter's thread ID is %dzwin32api.GetCurrentThreadId())r   CoInitializewin32apiGetCurrentThreadIdr   GetInterfaceFromGlobalIID_IDispatchwin32comclientDispatchr   Execprintr   CoUninitialize	traceback	print_exc)r   myThreadGITr   s       r   r   r   =   s     ..0k++FI4K4KL))&16%&L%DEFG	
   "s   CC C c                     / n[        U 5       HI  n[        R                  " SSSS5      n[        R                  " [
        XA45        UR                  U5        MK     U$ )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_newr   append)
numThreadsr   retihEvents        r   BeginThreadsSimpleMarshalr9   R   sU     C:''aD9,v.>?

6  Jr   c                    [        S[        R                  " 5       -  5        [        5       n[        R
                  R                  S5      nUR                  UR                  [        R                  5      nU " SU5      nSn  [        R                  " USS[        R                  5      nU[        R                  :  a6  U[        R                  [        U5      -   :  a  US-  nU[        U5      :  a  OpOmU[        R                  [        U5      -   :X  a  [        R                   " 5         O7[        S[        R"                  " 5       [        R$                  " 5       4-  5         M  UR)                  U5        AAg ! [&         a     M!  f = f)NzThe main thread is %dzPython.Interpreter   r      i  z:Waiting for thread to stop with interfaces=%d, gateways=%d)r)   r!   r"   r   r%   r&   r'   RegisterInterfaceInGlobal_oleobj_r   r$   r   MsgWaitForMultipleObjectsQS_ALLINPUTWAIT_OBJECT_0lenPumpWaitingMessages_GetInterfaceCount_GetGatewayCountKeyboardInterruptRevokeInterfaceFromGlobal)fnr.   r   r   eventsnumFinishedrcs          r   testrL   a   sU   	
!X%@%@%B
CD
+C__%%&:;F**6??I<S<STF6]FK
	554!7!7B Z---"z7O7ORUS 8 3 q #f+- .z//#f+==--/P 335y7Q7Q7STU * !!&)	 ! 		s   A/E6 35E6 )6E6 6
FF__main__i  z$Done with interfaces=%d, gateways=%dzDone.)__doc__r2   r+   r   r!   win32com.clientr%   r   r   r   r   r   r9   rL   __name__Sleepr*   rD   rE   r)   r   r   r   <module>rR      s   ,      

'*D z	"#NN3##%*i.H.H.Ja.O2++-y/I/I/KLM	

 	g r   