1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
U
X±dMAã@s’ddlZddlmZddlmZmZddlmZmZddl    Z    ddl
Z
ddl Z ddl m Z ddl mZe e¡Zejdkr ddlZddlZddlZGdd    „d    ejƒZd
Ze e¡ZejjjZe ejj ¡e ejj ¡eejj!ge_"ejj#e_$ejjj%Z%ejj ge%_"ejj#e%_$ee&ƒ 'd ¡Z(d d „Z)dd„Z*ejdkrHdd„Z+dd„Z,ndd„Z+dd„Z,e-e-dœdd„Z.dd„Z/Gdd„dƒZ0dd„Z1dd „Z2dS)!éN)ÚPath)ÚloadsÚdumps)Ú    b64encodeÚ    b64decode)Úcompat)ÚlogÚntc@s.eZdZdejjfdejjfdejjfgZdS)ÚSECURITY_ATTRIBUTESÚnLengthÚlpSecurityDescriptorÚbInheritHandleN)    Ú__name__Ú
__module__Ú __qualname__ÚctypesÚwintypesÚDWORDÚLPVOIDÚBOOLÚ_fields_©rrúSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PyInstaller/isolated/_parent.pyr
 s
 
 
ýr
éz    _child.pycCs
t||ƒS)aÄ
    Create a one-way pipe for sending data to child processes.
 
    Args:
        read_handle_inheritable:
            A boolean flag indicating whether the handle corresponding to the read end-point of the pipe should be
            marked as inheritable by subprocesses.
        write_handle_inheritable:
            A boolean flag indicating whether the handle corresponding to the write end-point of the pipe should be
            marked as inheritable by subprocesses.
 
    Returns:
        A read/write pair of file descriptors (which are just integers) on posix or system file handles on Windows.
 
    The pipe may be used either by this process or subprocesses of this process but not globally.
    )Ú_create_pipe_impl)Úread_handle_inheritableÚwrite_handle_inheritablerrrÚ create_pipe<srcCst|ƒS)zT
    Close the file descriptor (posix) or handle (Windows) belonging to a pipe.
    )Ú_close_pipe_endpoint_impl)Ú pipe_handlerrrÚclose_pipe_endpointPsr cCs†tj ¡}tj ¡}tƒ}t |¡|_d|_d|_tt     |¡t     |¡t     |¡dƒ}|s^t 
¡‚t   |j |¡t   |j |¡|j |j fS)NTr)rrÚHANDLEr
Úsizeofr r r Ú
CreatePipeÚbyrefÚWinErrorÚosÚset_handle_inheritableÚvalue)rrZ read_handleZ write_handleZsecurity_attributesÚ    succeededrrrrYs"
 
 ürcCst|ƒ}|st ¡‚dS©N)Ú CloseHandlerr%)rr)rrrrwsrcCs,t ¡\}}t ||¡t ||¡||fSr*)r&ÚpipeÚset_inheritable)Zread_fd_inheritableZwrite_fd_inheritableZread_fdZwrite_fdrrrr}s   cCst |¡dSr*)r&Úclose)Zpipe_fdrrrrˆs)Úread_from_parentÚwrite_to_parentcCsftjdkrtƒddœ}ntƒdtjd||giddœ}t ttƒt|ƒt|ƒg|¡\}}tj    |f|ŽS)zu
    Spawn a Python subprocess sending it the two file descriptors it needs to talk back to this parent process.
    r    F)ÚenvÚ    close_fdsTÚ handle_list)ÚlpAttributeList)r1r2Ú startupinfo)
r&ÚnameÚ_subprocess_envÚ
subprocessÚ STARTUPINFOrZ __wrap_pythonÚstrÚCHILD_PYÚPopen)r/r0Ú extra_kwargsÚcmdÚoptionsrrrÚchildŒs
þý"r@cCsLddlm}|d}dtjkr.|tjdg}tj ¡}tj |¡|d<|S)zM
    Define the environment variables to be readable in a child process.
    r)ÚCONFZpathexÚ
PYTHONPATH)ZPyInstaller.configrAr&ÚenvironÚcopyÚpathsepÚjoin)rAZ python_pathr1rrrr7§s 
 
r7c@s:eZdZdZd dd„Zdd„Zdd„Zd    d
„Zd d „ZdS)ÚPythona&
    Start and connect to a separate Python subprocess.
 
    This is the lowest level of public API provided by this module. The advantage of using this class directly is
    that it allows multiple functions to be evaluated in a single subprocess, making it faster than multiple calls to
    :func:`call`.
 
    The ``strict_mode`` argument controls behavior when the child process fails to shut down; if strict mode is enabled,
    an error is raised, otherwise only warning is logged. If the value of ``strict_mode`` is ``None``, the value of
    ``PyInstaller.compat.strict_collect_mode`` is used (which in turn is controlled by the
    ``PYINSTALLER_STRICT_COLLECT_MODE`` environment variable.
 
    Examples:
        To call some predefined functions ``x = foo()``, ``y = bar("numpy")`` and ``z = bazz(some_flag=True)`` all using
        the same isolated subprocess use::
 
            with isolated.Python() as child:
                x = child.call(foo)
                y = child.call(bar, "numpy")
                z = child.call(bazz, some_flag=True)
 
    NcCsd|_|dk    r|ntj|_dSr*)Ú_childrZstrict_collect_modeÚ _strict_mode)ÚselfZ strict_moderrrÚ__init__ËszPython.__init__cCs tddƒ\}}tddƒ\}}t||ƒ|_t|ƒt|ƒ~~tjdkrtt t |d¡d¡|_    t t |d¡d¡|_
nt |d¡|_    t |d¡|_
|  t j ¡|S)NFTr    rÚwbÚrb)rr@rHr r&r6ÚfdopenÚmsvcrtÚopen_osfhandleÚ _write_handleÚ _read_handleÚ_sendÚsysÚpath)rJZread_from_childr0r/Zwrite_to_childrrrÚ    __enter__Òs 
 zPython.__enter__c CsÈ|j d¡|j ¡d}z|jjddWnbtjk
rŽt d¡d}|j     ¡z|jjddWn tjk
rˆt d¡YnXYnX|j 
¡|j  
¡|` |`d|_|rÄ|j rÄt dƒ‚dS)    Nó
Fé)Útimeoutz6Timed out while waiting for the child process to exit!Téz;Timed out while waiting for the child process to be killed!)rQÚwriteÚflushrHÚwaitr8ÚTimeoutExpiredÚloggerÚwarningÚkillr.rRrIÚ RuntimeError)rJÚexc_typeÚexc_valÚexc_tbZshutdown_errorrrrÚ__exit__ôs& 
    
 
 
 
 
zPython.__exit__cOsb|jdkrtdƒ‚| |j|j|j||¡tt|j     ¡ƒƒ\}}|rH|Std|j
›d|ƒ‚dS)z¡
        Call a function in the child Python. Retrieve its return value. Usage of this method is identical to that
        of the :func:`call` function.
        Nz:An isolated.Python object must be used in a 'with' clause.zChild process call to z() failed with:
) rHrbrSÚ__code__Ú __defaults__Ú__kwdefaults__rrrRÚreadliner)rJÚfunctionÚargsÚkwargsÚokÚoutputrrrÚcalls
z Python.callcGs8|D]$}|j tt|ƒƒ¡|j d¡q|j ¡dS)NrW)rQr[rrr\)rJZobjectsÚobjectrrrrS0sz Python._send)N)    rrrÚ__doc__rKrVrfrprSrrrrrG´s 
"%rGc
Os0tƒ }|j|f|ž|ŽW5QR£SQRXdS)a¾
    Call a function with arguments in a separate child Python. Retrieve its return value.
 
    Args:
        function:
            The function to send and invoke.
        *args:
        **kwargs:
            Positional and keyword arguments to send to the function. These must be simple builtin types - not custom
            classes.
    Returns:
        The return value of the function. Again, these must be basic types serialisable by :func:`marshal.dumps`.
    Raises:
        RuntimeError:
            Any exception which happens inside an isolated process is caught and reraised in the parent process.
 
    To use, define a function which returns the information you're looking for. Any imports it requires must happen in
    the body of the function. For example, to safely check the output of ``matplotlib.get_data_path()`` use::
 
        # Define a function to be ran in isolation.
        def get_matplotlib_data_path():
            import matplotlib
            return matplotlib.get_data_path()
 
        # Call it with isolated.call().
        get_matplotlib_data_path = isolated.call(matplotlib_data_path)
 
    For single use functions taking no arguments like the above you can abuse the decorator syntax slightly to define
    and execute a function in one go. ::
 
        >>> @isolated.call
        ... def matplotlib_data_dir():
        ...     import matplotlib
        ...     return matplotlib.get_data_path()
        >>> matplotlib_data_dir
        '/home/brenainn/.pyenv/versions/3.9.6/lib/python3.9/site-packages/matplotlib/mpl-data'
 
    Functions may take positional and keyword arguments and return most generic Python data types. ::
 
        >>> def echo_parameters(*args, **kwargs):
        ...     return args, kwargs
        >>> isolated.call(echo_parameters, 1, 2, 3)
        (1, 2, 3), {}
        >>> isolated.call(echo_parameters, foo=["bar"])
        (), {'foo': ['bar']}
 
    Notes:
        To make a function behave differently if it's isolated, check for the ``__isolated__`` global. ::
 
            if globals().get("__isolated__", False):
                # We're inside a child process.
                ...
            else:
                # This is the master process.
                ...
 
    N)rGrp)rkrlrmÚisolatedrrrrp9s:rpcst ˆ¡‡fdd„ƒ}|S)aã
    Decorate a function so that it is always called in an isolated subprocess.
 
    Examples:
 
        To use, write a function then prepend ``@isolated.decorate``. ::
 
            @isolated.decorate
            def add_1(x):
                '''Add 1 to ``x``, displaying the current process ID.'''
                import os
                print(f"Process {os.getpid()}: Adding 1 to {x}.")
                return x + 1
 
        The resultant ``add_1()`` function can now be called as you would a
        normal function and it'll automatically use a subprocess.
 
            >>> add_1(4)
            Process 4920: Adding 1 to 4.
            5
            >>> add_1(13.2)
            Process 4928: Adding 1 to 13.2.
            14.2
 
    cstˆf|ž|ŽSr*)rp)rlrm©rkrrÚwrapped‘szdecorate.<locals>.wrapped)Ú    functoolsÚwraps)rkrurrtrÚdecoratewsrx)3r&ÚpathlibrÚmarshalrrÚbase64rrrvr8rTZ PyInstallerrrÚloggingÚ    getLoggerrr_r6rOrZctypes.wintypesÚ    Structurer
ZHANDLE_FLAG_INHERITÚPOINTERZLPSECURITY_ATTRIBUTESÚwindllÚkernel32r#rr!rÚargtypesrÚrestyper+Ú__file__Ú    with_namer;rr rrÚintr@r7rGrprxrrrrÚ<module> sP   
 
 
  ü
 
 
 
  >