관리-도구
편집 파일: multiprocess.cpython-38.pyc
U )�e։ � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddlmZ ddl m Z ddl mZ ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ zddlmZ W n ek r� ddlmZ Y nX ddlmZ dd lmZ zddl m!Z! W n ek �r$ ddl Z Y nX dZ"e�#e$�Z%d a& a' a( a) a*a+G dd� de,�Z-dd� Z.G dd� d�Z/G dd� de�Z0dd� Z1G dd� de�Z2dd� Z3dd� Z4G dd � d e�Z5dS )!a� Overview ======== The multiprocess plugin enables you to distribute your test run among a set of worker processes that run tests in parallel. This can speed up CPU-bound test runs (as long as the number of work processeses is around the number of processors or cores available), but is mainly useful for IO-bound tests that spend most of their time waiting for data to arrive from someplace else. .. note :: See :doc:`../doc_tests/test_multiprocess/multiprocess` for additional documentation and examples. Use of this plugin on python 2.5 or earlier requires the multiprocessing_ module, also available from PyPI. .. _multiprocessing : http://code.google.com/p/python-multiprocessing/ How tests are distributed ========================= The ideal case would be to dispatch each test to a worker process separately. This ideal is not attainable in all cases, however, because many test suites depend on context (class, module or package) fixtures. The plugin can't know (unless you tell it -- see below!) if a context fixture can be called many times concurrently (is re-entrant), or if it can be shared among tests running in different processes. Therefore, if a context has fixtures, the default behavior is to dispatch the entire suite to a worker as a unit. Controlling distribution ^^^^^^^^^^^^^^^^^^^^^^^^ There are two context-level variables that you can use to control this default behavior. If a context's fixtures are re-entrant, set ``_multiprocess_can_split_ = True`` in the context, and the plugin will dispatch tests in suites bound to that context as if the context had no fixtures. This means that the fixtures will execute concurrently and multiple times, typically once per test. If a context's fixtures can be shared by tests running in different processes -- such as a package-level fixture that starts an external http server or initializes a shared database -- then set ``_multiprocess_shared_ = True`` in the context. These fixtures will then execute in the primary nose process, and tests in those contexts will be individually dispatched to run in parallel. How results are collected and reported ====================================== As each test or suite executes in a worker process, results (failures, errors, and specially handled exceptions like SkipTest) are collected in that process. When the worker process finishes, it returns results to the main nose process. There, any progress output is printed (dots!), and the results from the test run are combined into a consolidated result set. When results have been received for all dispatched tests, or all workers have died, the result summary is output as normal. Beware! ======= Not all test suites will benefit from, or even operate correctly using, this plugin. For example, CPU-bound tests will run more slowly if you don't have multiple processors. There are also some differences in plugin interactions and behaviors due to the way in which tests are dispatched and loaded. In general, test loading under this plugin operates as if it were always in directed mode instead of discovered mode. For instance, doctests in test modules will always be found when using this plugin with the doctest plugin. But the biggest issue you will face is probably concurrency. Unless you have kept your tests as religiously pure unit tests, with no side-effects, no ordering issues, and no external dependencies, chances are you will experience odd, intermittent and unexplainable failures and errors when using this plugin. This doesn't necessarily mean the plugin is broken; it may mean that your test suite is not safe for concurrency. New Features in 1.1.0 ===================== * functions generated by test generators are now added to the worker queue making them multi-threaded. * fixed timeout functionality, now functions will be terminated with a TimedOutException exception when they exceed their execution time. The worker processes are not terminated. * added ``--process-restartworker`` option to restart workers once they are done, this helps control memory usage. Sometimes memory leaks can accumulate making long runs very difficult. * added global _instantiate_plugins to configure which plugins are started on the worker processes. � N)�TextTestRunner)�failure)�loader)�Plugin)�bytes_)�TextTestResult)�ContextSuite)�test_address)�_WritelnDecorator)�Empty)�warn)�StringIOc @ s e Zd Zddd�Zdd� ZdS )�TimedOutException� Timed Outc C s || _ d S �N)�value)�selfr � r �G/opt/hc_python/lib/python3.8/site-packages/nose/plugins/multiprocess.py�__init__� s zTimedOutException.__init__c C s t | j�S r )�reprr �r r r r �__str__� s zTimedOutException.__str__N)r )�__name__� __module__�__qualname__r r r r r r r � s r c C s~ zZddl m} ma t�tjtj�}| � }t�tj|� |j|j|j|j |j f\aaaa a W n tk rx tdt � Y nX d S )Nr )�Manager�ProcesszKmultiprocessing module is not available, multiprocess plugin cannot be used)�multiprocessingr r �signal�SIGINT�SIG_IGN�Queue�Pool�Event�Value�Array�ImportErrorr �RuntimeWarning)r �old�mr r r � _import_mp� s ��r+ c @ s, e Zd Zdd� Zdd� Zdd� Zdd� Zd S ) �TestLetc C s<