a c$@sUddlZddlZddlZddlZddlmZddlmZmZddl m Z m Z m Z m Z mZmZmZmZddlmZmZmZddlmZddlmZdd lmZdd lmZmZdd lm Z m!Z!m"Z"dd l#m$Z$m%Z%dd l&m'Z'dZ(edZ)e$dZ*e$ee"e+d<e$dZ,e$e ee"e-fe+d<e$dZ.e$ee+d<ddde de)fe/e0e ee)dddZ1edddZ2ddddZ3e4dkre3dS)N)deque)module_from_specspec_from_file_location)CallableDequeListOptionalSetTupleTypeVarcast) current_time get_asynclibget_cancelled_exc_class)BrokenWorkerProcess) open_process)CapacityLimiter) CancelScope fail_after)ByteReceiveStreamByteSendStreamProcess)RunVarcheckpoint_if_cancelled)BufferedByteReceiveStreami,T_Retval_process_pool_workers_process_pool_idle_workers_default_process_limiterF) cancellablelimiter.)funcargsr r!returnc sttdfdd }tIdHtjd||ftjd}ztt}Wn>t yt t }t t |t Yn0|pt4IdH|r|\}jdur~ttjtttjt}g} |r4||ddtkr q4|\}| qtd d *| D]IdHqDWdn1sp0Yqqtj d d t!g} t"| t#j$t#j$d IdHzttjtttjt%d &dIdH} Wdn1s0Y| dkr t'd| t(tj)ddd} tjdtj*| ftjd} || IdHWnRt't+fyvYn8t,y}zt'd|WYd}~n d}~00-t| d zTtt.||IdHWvr|tfWdWdIdHSnvr6|tf0Wdn1sN0YWdIdHq1IdHs|0YdS)a Call the given function with the given arguments in a worker process. If the ``cancellable`` option is enabled and the task waiting for its completion is cancelled, the worker process running it will be abruptly terminated using SIGKILL (or ``terminateProcess()`` on Windows). :param func: a callable :param args: positional arguments for the callable :param cancellable: ``True`` to allow cancellation of the operation while it's running :param limiter: capacity limiter to use to limit the total amount of processes running (if omitted, the default limiter is used) :return: an awaitable that yields the return value of the function. ) pickled_cmdr$c s.z^|IdHddIdH}|d\}}|dvrHtd|t|IdH}Wnty}zzDt dd IdHWdn1s0YWnt yYn0t |t rnt|WYd}~n d}~00t|}|dkr&t |ts J|n|SdS) N 2 )RETURN EXCEPTION-Worker process returned unexpected response: TZshieldr*)sendZ receive_untilsplit RuntimeErrorZreceive_exactlyint BaseExceptiondiscardkillracloseProcessLookupError isinstancerrpickleloads)r%responsestatuslengthZpickled_responseexcretvalZbufferedprocessstdinworkers]/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/anyio/to_process.pysend_raw_command2s2  0    z"run_sync..send_raw_commandNrun)protocolrr Tr,z-uz-m)r@stdoutREADY r+__main____file__initz*Error during worker process initialization)/bytesobjectrr7dumpsHIGHEST_PROTOCOLrgetr LookupErrorsetrrZ#setup_process_pool_exit_at_shutdowncurrent_default_process_limiterpop returncoder rr@rrrGrWORKER_MAX_IDLE_TIMEpopleftr3removeappendrr4sys executable__name__r subprocessPIPErZreceivergetattrmodulespathrr1addr)r"r r!r#rDrequestZ idle_workersZ idle_sincenowZkilled_processescommandmessagemain_module_pathpickledr<rBr>rCrun_syncs!             2     0    $ rk)r$cCs@z tWSty:ttp$d}t||YS0dS)z Return the capacity limiter that is used by default to limit the number of worker processes. :return: a capacity limiter object N)rrRrSros cpu_countrT)r!rBrBrCrUs    rUc Cstj}tj}ttjt_ttjdt_|jdd}}zt |j^}}Wn:t ybYdSt y}z|}WYd}~nd}~00|dkr|\}}z ||}Wn(t y}z|}WYd}~n d}~00n|dkrZ|\t_ }tj d=|rZz:td|} | r,| jr,t| } | j| | tj d<Wn*t yX}z|}WYd}~n d}~00z4|durzd} t|tj} nd} t|tj} Wn<t y}z"|}d} t|tj} WYd}~n d}~00|jd | t| f|j| t|tr2|q2dS) NwrJrErMrK __mp_main__r*r)s%s %d )r\r@rGopenrmdevnullbufferwriter7loadEOFErrorr1rcrbrloaderr exec_modulerPrQlenr6 SystemExit) r@rGr= exceptionrgr#r<r"rispecmainr:rjrBrBrCprocess_workersX         $  r~rK)5rmr7r_r\ collectionsrimportlib.utilrrtypingrrrrr r r r Z_core._eventlooprrrZ_core._exceptionsrZ_core._subprocessesrZ_core._synchronizationrZ _core._tasksrrabcrrrZlowlevelrrZstreams.bufferedrrXrr__annotations__rfloatrrOboolrkrUr~r^rBrBrBrCsF  (      <