File: //usr/local/lib/python3.10/test/__pycache__/test_multiprocessing_main_handling.cpython-310.pyc
o
�iE. � @ sP d dl mZ d dlmZ e�d� d dlZd dlZd dlZd dlZd dl Z d dl
Z d dlZd dlmZ d dl
mZmZmZmZmZ ejrIe�d��d dlZee�� �Ze�� ejZdZd Zed
fdd�Zed
fdd�ZdZddd�Z G dd� d�Z!G dd� de!ej"�Z#G dd� de!ej"�Z$G dd� de!ej"�Z%dd� Z&e'dkr�e�(� dS dS )� )�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()
Fc C s. 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_scripto s �r � c C s t | |||||�}t�� |S �N)r r
r )Zzip_dirZzip_basenameZpkg_namer r �depthr r r r �_make_test_zip_pkgy s
�r zPimport sys, os.path, runpy
sys.path.insert(0, %s)
runpy._run_module_as_main(%r)
c C s: |d u rd}nt |�}t||f }t| ||�}t�� |S )Nzos.path.dirname(__file__))�repr�
launch_sourcer r
r )r r �module_name�pathr r r r r �_make_launch_script� s r c @ s� e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd� Zd d!� ZdS )"�MultiProcessingCmdLineMixinNc C s"