L i7ddlZddlZddlZddlZddlZddlZddlZddlmZ ddl m Z ddl m Z ddlmZmZej"dkre dz Z gdZej&d k7red d gz Zdadadd Zdd ZdZddZdZdZdZdZdZdZdZGdde Z Gdde Z!e Z"e"ejFjHd<e!ejFjHd<y)N) get_context) BaseContext)_MAX_WINDOWS_WORKERS) LokyProcessLokyInitMainProcess) )lokyloky_init_mainspawnwin32fork forkserverc|xs txsd}|dk(rtjdt t |S#t $rt d|dt dwxYw)Nr rzu`fork` start method should not be used with `loky` as it does not respect POSIX. Try using `spawn` or `loky` instead.zUnknown context 'z'. Value should be in .)_DEFAULT_START_METHODwarningswarn UserWarningmp_get_context ValueError START_METHODS)methods k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/joblib/externals/loky/backend/context.pyrr*sr  6, 6F   )    f%%  x'=oQ    s : Acdt |s td||tvsJd|dt|ay)Nzcontext has already been set'z/' is not a valid start_method. It should be in )r RuntimeErrorr)rforces rset_start_methodr >sK(9:: >V}4 F8B /  4 #ctSN)rr!rget_start_methodr%Js  r!ctjxsd}tjdk(rt |t }t |}tt ||d}|s|S||kr t|dSt\}}|dk7r|S|8tjd|dtj|j|S)aReturn the number of CPUs the current process can use. The returned number of CPUs accounts for: * the number of CPUs in the system, as given by ``multiprocessing.cpu_count``; * the CPU affinity settings of the current process (available on some Unix systems); * Cgroup CPU bandwidth limit (available on Linux only, typically set by docker and similar container orchestration systems); * the value of the LOKY_MAX_CPU_COUNT environment variable if defined. and is given as the minimum of these constraints. If ``only_physical_cores`` is True, return the number of physical cores instead of the number of logical cores (hyperthreading / SMT). Note that this option is not enforced if the number of usable cores is controlled in any other way such as: process affinity, Cgroup restricted CPU bandwidth or the LOKY_MAX_CPU_COUNT environment variable. If the number of physical cores is not found, return the number of logical cores. Note that on Windows, the returned number of CPUs cannot exceed 61 (or 60 for Python < 3.10), see: https://bugs.python.org/issue26903. It is also always larger or equal to 1. rr not foundzFCould not find the number of physical cores for the following reason: z Returning the number of logical cores instead. You can silence this warning by setting LOKY_MAX_CPU_COUNT to the number of cores you want to use.)os cpu_countsysplatformminr_cpu_count_usermax_count_physical_coresrr tracebackprint_tb __traceback__)only_physical_cores os_cpu_countcpu_count_useraggregate_cpu_countcpu_count_physical exceptions rr)r)Ns6<<>&QL ||w <)=> $\2Nc,?C "" $>1%%$9$;! [(!!  ""+-3 3  9223 r!cd}d}d}tjj|rDt|5}|j j j \}}dddntjj|rtjj|ret|5}|j j }dddt|5}|j j }dddnd}d}dk(r|St|}t}|dkDr|dkDrtj||z S|S#1swYJxYw#1swYxYw#1swYbxYw)Nz/sys/fs/cgroup/cpu.maxz#/sys/fs/cgroup/cpu/cpu.cfs_quota_usz$/sys/fs/cgroup/cpu/cpu.cfs_period_usr.ir) r(pathexistsopenreadstripsplitintmathceil)r4 cpu_max_fnamecfs_quota_fnamecfs_period_fnamefh cpu_quota_us cpu_period_uss r_cpu_count_cgrouprIsP,M;O= ww~~m$-  DB*,'')//*;*A*A*C 'L- D D  (RWW^^  \\W $!  \\X %!=!? %(>s||n&MN N  !v&8%99LMN N ". y (( ) ()sB B## B:,B55B:c tjdjdd}|jj }|Dchc]}|j dr|}}t |Scc}w#YnxYwtjdjdd}|jj }|Dchc]}|j ds|ncc}w}}t |S)Nzlscpu --parse=coreTcapture_outputtext#zcat /proc/cpuinfozcore id) subprocessrunr?stdout splitlines startswithrP)cpu_infolines rr`r` s >> & & (D ??--/%-JTT__S5IDJJ8}K  ~~!!#DtH))+H!)HT__Y-GHHHH x=s0AA3A.A.! A3.A33A7>CCc d}tjd|jdd}|jj }t |dS#YnxYwtjdjdd}|jj }|Dcgc]}|s|dk7s |jdd !ncc}w}}t tt |S) NzC-Command (Get-CimInstance -ClassName Win32_Processor).NumberOfCoreszpowershell.exe Trfrz&wmic CPU Get NumberOfCores /Format:csvzNode,NumberOfCores,r)rjrkr?rlrmr@summap)cmdrols rraras  S>>cU # ) ) +  ??--/8A;  ~~0668 H ))+H!)aA9M4M QH s3! ""sAAA C(C.Cc|tjdjdd}|j}t |S)Nzsysctl -n hw.physicalcpuTrf)rjrkr?rlr@)ros rrbrb7s7~~"((* H H x=r!ceZdZdZdZeZeeZd dZ ddZ e jdk7r ddZ dZd Zd Zdd Zd Zyy) LokyContextz#Context relying on the LokyProcess.r Nc@ddlm}||||jS)Returns a queue objectr)Queuereducersctx)queuesr|r)selfmaxsizer~r|s rr|zLokyContext.QueueHs!WxT5E5E5GHHr!c>ddlm}|||jS)r{r) SimpleQueuer})rrr)rr~rs rrzLokyContext.SimpleQueueNs'H$2B2B2DEEr!rc ddlm}||S)zReturns a semaphore objectr) Semaphore)value) synchronizer)rrrs rrzLokyContext.SemaphoreZs .5) )r!cddlm}||S)z"Returns a bounded semaphore objectr)BoundedSemaphore)rr)rrrs rrzLokyContext.BoundedSemaphore`s 5#E* *r!cddlm}|S)zReturns a lock objectr)Lock)rr)rrs rrzLokyContext.Lockfs )6Mr!cddlm}|S)zReturns a recurrent lock objectr)RLock)rr)rrs rrzLokyContext.RLockl *7Nr!cddlm}||S)zReturns a condition objectr) Condition)rr)rlockrs rrzLokyContext.Conditionrs .T? "r!cddlm}|S)zReturns an event objectr)Event)rr)rrs rrzLokyContext.Eventxrr!)rNr#)r)__name__ __module__ __qualname____doc___namerrS staticmethodr)r|rr*r+rrrrrrr$r!rryryAs\- EGY'II F  ||w  *  +      #  Ir!ryceZdZdZdZeZy)LokyInitMainContextaExtra context with LokyProcess, which does load the main module This context is used for compatibility in the case ``cloudpickle`` is not present on the running system. This permits to load functions defined in the ``main`` module, using proper safeguards. The declaration of the ``executor`` should be protected by ``if __name__ == "__main__":`` and the functions and variable used from main should be out of this block. This mimics the default behavior of multiprocessing under Windows and the behavior of the ``spawn`` start method on a posix system. For more details, see the end of the following section of python doc https://docs.python.org/3/library/multiprocessing.html#multiprocessing-programming r N)rrrrrrrSr$r!rrrs  E!Gr!rr r r#)F)%r(r*rArjr0rmultiprocessingmprrmultiprocessing.contextrconcurrent.futures.processrprocessrr version_inforr+rr_r r%r)rIrXr-r/r`rarbryrctx_lokycontext_concrete_contextsr$r!rrs 9/;6g/!33 <<7fl++M ( #!>B! H!H E%)P&#2;+;|"+"( =(0 f%2E2G ./r!