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.10/test/__pycache__/test_multiprocessing_main_handling.cpython-310.pyc
o

�iE.�@sPddlmZddlmZe�d�ddlZddlZddlZddlZddl	Z	ddl
Z	ddlZddlmZddl
mZmZmZmZmZejrIe�d��ddlZee���Ze��ejZdZd	Zed
fdd�Zed
fdd�ZdZddd�Z Gdd�d�Z!Gdd�de!ej"�Z#Gdd�de!ej"�Z$Gdd�de!ej"�Z%dd�Z&e'dkr�e�(�dSdS)�)�support)�
import_helper�_multiprocessingN)�	os_helper)�make_pkg�make_script�make_zip_pkg�make_zip_script�assert_python_okztest is not helpful for PGOa�# 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||||�}|dkrt|dd�t��|S)N�
check_siblingZsibling�)r�	importlib�invalidate_caches)�
script_dir�script_basename�source�omit_suffix�	to_return�r�D/usr/local/lib/python3.10/test/test_multiprocessing_main_handling.py�_make_test_scriptos�r�cCst||||||�}t��|S�N)rr
r)Zzip_dirZzip_basenameZpkg_namerr�depthrrrr�_make_test_zip_pkgys

�rzPimport sys, os.path, runpy
sys.path.insert(0, %s)
runpy._run_module_as_main(%r)
cCs:|durd}nt|�}t||f}t|||�}t��|S)Nzos.path.dirname(__file__))�repr�
launch_sourcerr
r)rr�module_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"|jtvr|�d|j�dSdS)Nz%r start method not available)�start_method�AVAILABLE_START_METHODSZskipTest)�selfrrr�setUp�s
�z!MultiProcessingCmdLineMixin.setUpcCsbtdkrtd|�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_outputcGs8	|||jf}t|ddi�\}}}|�||||�dS)NF�-�OZ
__isolated)�sys�flags�optimizer!r
r,)r#r)Zcmd_line_switchesZrun_args�rcr*r+rrr�
_check_script�sz)MultiProcessingCmdLineMixin._check_scriptcCsBt���}t|d�}|�|�Wd�dS1swYdS)N�script�r�temp_dirrr3�r#rr)rrr�test_basic_script�s

"�z-MultiProcessingCmdLineMixin.test_basic_scriptcCsFt���}t|ddd�}|�|�Wd�dS1swYdS)Nr4T)rr5r7rrr�test_basic_script_no_suffix�s
�"�z7MultiProcessingCmdLineMixin.test_basic_script_no_suffixcCsdt}t���"}t|d|d�}|�|�t|d|dd�}|�|�Wd�dS1s+wYdS)NZipython�rT)rr)�$test_source_main_skipped_in_childrenrr6rr3)r#rrr)Zscript_no_suffixrrr�test_ipython_workaround�s
�
�"�z3MultiProcessingCmdLineMixin.test_ipython_workaroundcCsdt���$}t|d�}tj|dd�t�|�t�|�}|�	|�Wd�dS1s+wYdS)Nr4T��doraise)
rr6r�
py_compile�compile�os�remover�make_legacy_pycr3)r#rr)�pyc_filerrr�test_script_compiled�s



"�z0MultiProcessingCmdLineMixin.test_script_compiledcCsL|j}t���}t|d|d�}|�|�Wd�dS1swYdS)N�__main__r:)�main_in_children_sourcerr6rr3)r#rrr)rrr�test_directory�s
�"�z*MultiProcessingCmdLineMixin.test_directorycCsn|j}t���&}t|d|d�}tj|dd�t�|�t�	|�}|�
|�Wd�dS1s0wYdS)NrFr:Tr=)rGrr6rr?r@rArBrrCr3)r#rrr)rDrrr�test_directory_compiled�s
�

"�z3MultiProcessingCmdLineMixin.test_directory_compiledcCs\|j}t���}t|d|d�}t|d|�\}}|�|�Wd�dS1s'wYdS)NrFr:�test_zip)rGrr6rr	r3)r#rrr)�zip_name�run_namerrr�test_zipfile�s
�"�z(MultiProcessingCmdLineMixin.test_zipfilecCsj|j}t���$}t|d|d�}tj|dd�}t|d|�\}}|�|�Wd�dS1s.wYdS)NrFr:Tr=rJ)rGrr6rr?r@r	r3)r#rrr)�
compiled_namerKrLrrr�test_zipfile_compiled�s
�"�z1MultiProcessingCmdLineMixin.test_zipfile_compiledcCsdt���$}tj�|d�}t|�t|d�}t|dd�}|�|�Wd�dS1s+wYdS)N�test_pkgr�launchztest_pkg.check_sibling)	rr6rAr�joinrrrr3)r#r�pkg_dirr)�launch_namerrr�test_module_in_package�s

�"�z2MultiProcessingCmdLineMixin.test_module_in_packagecCsXt���}t|ddd�\}}t|dd|�}|�|�Wd�dS1s%wYdS)NrJrPr4rQztest_pkg.script�rr6rrr3�r#rrKrLrTrrr�!test_module_in_package_in_zipfile�s

"�z=MultiProcessingCmdLineMixin.test_module_in_package_in_zipfilecCs\t��� }t|ddddd�\}}t|dd|�}|�|�Wd�dS1s'wYdS)NrJrPr4�)rrQztest_pkg.test_pkg.scriptrVrWrrr�$test_module_in_subpackage_in_zipfile�s

"�z@MultiProcessingCmdLineMixin.test_module_in_subpackage_in_zipfilecCsn|j}t���&}tj�|d�}t|�t|d|d�}t|dd�}|�	|�Wd�dS1s0wYdS)NrPrFr:rQ)
rGrr6rArrRrrrr3)r#rrrSr)rTrrr�test_packages
�"�z(MultiProcessingCmdLineMixin.test_packagecCs�|j}t���7}tj�|d�}t|�t|d|d�}tj	|dd�}t�
|�t�|�}t
|dd�}|�|�Wd�dS1sAwYdS)NrPrFr:Tr=rQ)rGrr6rArrRrrr?r@rBrrCrr3)r#rrrSr)rNrDrTrrr�test_package_compileds
�

"�z1MultiProcessingCmdLineMixin.test_package_compiled)�__name__�
__module__�__qualname__ZmaxDiffr$r,r3r8r9r<rErHrIrMrOrUrXrZr[r\rrrrr �s$	
		
r c@�eZdZdZeZdS)�SpawnCmdLineTest�spawnN�r]r^r_r!r;rGrrrrra�rac@r`)�ForkCmdLineTest�forkN)r]r^r_r!�test_sourcerGrrrrre!rdrec@r`)�ForkServerCmdLineTest�
forkserverNrcrrrrrh%rdrhcCst��dSr)r�
reap_childrenrrrr�tearDownModule)srkrFr))�testrZtest.supportr�
import_moduler
�importlib.machineryZunittestr/rAZos.pathr?rZtest.support.script_helperrrrr	r
ZPGOZSkipTest�multiprocessing�set�get_all_start_methodsr"Z*skip_if_broken_multiprocessing_synchronizer%rgr;rrrrr ZTestCaserarerhrkr]�mainrrrr�<module>sF

,$
�
�


�