HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_multiprocessing_main_handling.cpython-37.opt-1.pyc
B

��g�-�@s8ddlmZe�d�ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZmZejrze�d��ddlZee���Ze�d�ejZdZdZed	fd
d�Zedfd
d�ZdZddd�ZGdd�d�ZGdd�deej�ZGdd�deej�Z Gdd�deej�Z!dd�Z"e#dk�r4e�$�dS)�)�supportZ_multiprocessingN)�make_pkg�make_script�make_zip_pkg�make_zip_script�assert_python_okztest is not helpful for PGOzmultiprocessing.synchronizea�# multiprocessing includes all sorts of shenanigans to make __main__
# attributes accessible in the subprocess in a pickle compatible way.

# We run the "doesn't work in the interactive interpreter" example from
# the docs to make sure it *does* work from an executed __main__,
# regardless of the invocation mechanism

import sys
import time
from multiprocessing import Pool, set_start_method

# We use this __main__ defined function in the map call below in order to
# check that multiprocessing in correctly running the unguarded
# code in child processes and then making it available as __main__
def f(x):
    return x*x

# Check explicit relative imports
if "check_sibling" in __file__:
    # We're inside a package and not in a __main__.py file
    # so make sure explicit relative imports work correctly
    from . import sibling

if __name__ == '__main__':
    start_method = sys.argv[1]
    set_start_method(start_method)
    results = []
    with Pool(5) as pool:
        pool.map_async(f, [1, 2, 3], callback=results.extend)
        start_time = time.monotonic()
        while not results:
            time.sleep(0.05)
            # up to 1 min to report the results
            dt = time.monotonic() - start_time
            if dt > 60.0:
                raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt)

    results.sort()
    print(start_method, "->", results)

    pool.join()
a�# __main__.py files have an implied "if __name__ == '__main__'" so
# multiprocessing should always skip running them in child processes

# This means we can't use __main__ defined functions in child processes,
# so we just use "int" as a passthrough operation below

if __name__ != "__main__":
    raise RuntimeError("Should only be called as __main__!")

import sys
import time
from multiprocessing import Pool, set_start_method

start_method = sys.argv[1]
set_start_method(start_method)
results = []
with Pool(5) as pool:
    pool.map_async(int, [1, 4, 9], callback=results.extend)
    start_time = time.monotonic()
    while not results:
        time.sleep(0.05)
        # up to 1 min to report the results
        dt = time.monotonic() - start_time
        if dt > 60.0:
            raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt)

results.sort()
print(start_method, "->", results)

pool.join()
FcCs.t||||�}|dkr"t|dd�t��|S)N�
check_siblingZsibling�)r�	importlib�invalidate_caches)�
script_dir�script_basename�source�omit_suffix�	to_return�r�C/usr/local/lib/python3.7/test/test_multiprocessing_main_handling.py�_make_test_scriptmsr�cCst||||||�}t��|S)N)rr
r)Zzip_dirZzip_basenameZpkg_namer
r�depthrrrr�_make_test_zip_pkgws
rzPimport sys, os.path, runpy
sys.path.insert(0, %s)
runpy._run_module_as_main(%r)
cCs:|dkrd}nt|�}t||f}t|||�}t��|S)Nzos.path.dirname(__file__))�repr�
launch_sourcerr
r)rr
Zmodule_name�pathrrrrr�_make_launch_script�src@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�ZdS)"�MultiProcessingCmdLineMixinNcCs|jtkr|�d|j�dS)Nz%r start method not available)�start_method�AVAILABLE_START_METHODSZskipTest)�selfrrr�setUp�s
z!MultiProcessingCmdLineMixin.setUpcCsbtdkr td|�tt|��|�|d�|�|�d�d�d|j}|�|�d���|�dS)NrzOutput from test script %r:rzutf-8r	z%s -> [1, 4, 9])�verbose�printrZassertEqual�decoder�strip)r�script_nameZ	exit_code�out�errZexpected_resultsrrr�
_check_output�s
z)MultiProcessingCmdLineMixin._check_outputcGsL|ddtjjf7}|||jf}t|ddi�\}}}|�||||�dS)N�-�OZ
__isolatedF)�sys�flags�optimizerrr')rr$Zcmd_line_switchesZrun_argsZrcr%r&rrr�
_check_script�sz)MultiProcessingCmdLineMixin._check_scriptc	Cs,t���}t|d�}|�|�WdQRXdS)N�script)r�temp_dirrr-)rrr$rrr�test_basic_script�s

z-MultiProcessingCmdLineMixin.test_basic_scriptc	Cs0t���}t|ddd�}|�|�WdQRXdS)Nr.T)r)rr/rr-)rrr$rrr�test_basic_script_no_suffix�s
z7MultiProcessingCmdLineMixin.test_basic_script_no_suffixc	CsNt}t���8}t|d|d�}|�|�t|d|dd�}|�|�WdQRXdS)NZipython)rT)rr)�$test_source_main_skipped_in_childrenrr/rr-)rrrr$Zscript_no_suffixrrr�test_ipython_workaround�s

z3MultiProcessingCmdLineMixin.test_ipython_workaroundc	CsNt���<}t|d�}tj|dd�t�|�t�|�}|�|�WdQRXdS)Nr.T)�doraise)	rr/r�
py_compile�compile�os�remove�make_legacy_pycr-)rrr$�pyc_filerrr�test_script_compiled�s



z0MultiProcessingCmdLineMixin.test_script_compiledc	Cs6|j}t���}t|d|d�}|�|�WdQRXdS)N�__main__)r)�main_in_children_sourcerr/rr-)rrrr$rrr�test_directory�s

z*MultiProcessingCmdLineMixin.test_directoryc	CsX|j}t���@}t|d|d�}tj|dd�t�|�t�|�}|�	|�WdQRXdS)Nr<)rT)r4)
r=rr/rr5r6r7r8r9r-)rrrr$r:rrr�test_directory_compiled�s


z3MultiProcessingCmdLineMixin.test_directory_compiledc	CsF|j}t���.}t|d|d�}t|d|�\}}|�|�WdQRXdS)Nr<)r�test_zip)r=rr/rrr-)rrrr$�zip_name�run_namerrr�test_zipfile�s
z(MultiProcessingCmdLineMixin.test_zipfilec	CsT|j}t���<}t|d|d�}tj|dd�}t|d|�\}}|�|�WdQRXdS)Nr<)rT)r4r@)r=rr/rr5r6rr-)rrrr$�
compiled_namerArBrrr�test_zipfile_compiled�s
z1MultiProcessingCmdLineMixin.test_zipfile_compiledc	CsNt���<}tj�|d�}t|�t|d�}t|dd�}|�|�WdQRXdS)N�test_pkgr�launchztest_pkg.check_sibling)	rr/r7r�joinrrrr-)rr�pkg_dirr$�launch_namerrr�test_module_in_package�s

z2MultiProcessingCmdLineMixin.test_module_in_packagec	CsBt���0}t|ddd�\}}t|dd|�}|�|�WdQRXdS)Nr@rFr.rGztest_pkg.script)rr/rrr-)rrrArBrJrrr�!test_module_in_package_in_zipfile�s
z=MultiProcessingCmdLineMixin.test_module_in_package_in_zipfilec	CsFt���4}t|ddddd�\}}t|dd|�}|�|�WdQRXdS)Nr@rFr.�)rrGztest_pkg.test_pkg.script)rr/rrr-)rrrArBrJrrr�$test_module_in_subpackage_in_zipfile�s
z@MultiProcessingCmdLineMixin.test_module_in_subpackage_in_zipfilec	CsX|j}t���@}tj�|d�}t|�t|d|d�}t|dd�}|�	|�WdQRXdS)NrFr<)rrG)
r=rr/r7rrHrrrr-)rrrrIr$rJrrr�test_packages
z(MultiProcessingCmdLineMixin.test_packagec	Csz|j}t���b}tj�|d�}t|�t|d|d�}tj	|dd�}t�
|�t�|�}t|dd�}|�
|�WdQRXdS)NrFr<)rT)r4rG)r=rr/r7rrHrrr5r6r8r9rr-)rrrrIr$rDr:rJrrr�test_package_compileds


z1MultiProcessingCmdLineMixin.test_package_compiled)�__name__�
__module__�__qualname__ZmaxDiffrr'r-r0r1r3r;r>r?rCrErKrLrNrOrPrrrrr�s"	
		
rc@seZdZdZeZdS)�SpawnCmdLineTestZspawnN)rQrRrSrr2r=rrrrrTsrTc@seZdZdZeZdS)�ForkCmdLineTest�forkN)rQrRrSr�test_sourcer=rrrrrUsrUc@seZdZdZeZdS)�ForkServerCmdLineTestZ
forkserverN)rQrRrSrr2r=rrrrrX#srXcCst��dS)N)rZ
reap_childrenrrrr�tearDownModule'srYr<)N)%Ztestr�
import_moduler
Zimportlib.machineryZunittestr*r7Zos.pathr5Ztest.support.script_helperrrrrrZPGOZSkipTestZmultiprocessing�setZget_all_start_methodsrr rWr2rrrrrZTestCaserTrUrXrYrQ�mainrrrr�<module>s:


,!