i.dZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddl mZddl mZdd l mZe rdd lmZgd Zd Zejd dejDZdZdZdejeedejeejefdZdZddZddZ edZ!edZ"ddZ#eje#_dZ$edZ%dS)z%Routines common to all posix systems.N)_ntuples)MACOSTimeoutExpired)debug)memoize) usage_percent) _psutil_osx) pid_existswait_pid disk_usageget_terminal_mapc||dkrdS tj|ddS#t$rYdSt$rYdSwxYw)z6Check whether pid exists in the current process table.rTF)oskillProcessLookupErrorPermissionError)pids =C:\PYTHON\_runtimes\venv\Lib\site-packages\psutil/_psposix.pyr r sj axx t  Qt uu tts! ; ;; Negsignalc*i|]}|j|j S)namevalue.0xs r r4s ;;;q!&17(;;;cF t|S#t$r|cYSwxYw)z+Convert a negative signal value to an enum.)r ValueError)nums rnegsig_to_enumr$8s7~~  s   ctj|rtj|Stj|r"t tj| Sd|}t |)z.Convert a os.waitpid() status to an exit code.zunknown process exit status )r WIFEXITED WEXITSTATUS WIFSIGNALEDr$WTERMSIGr")statusmsgs rconvert_exit_coder,@sp |F&~f%%% ~f4r{6222333" 4 3 3C S//r monotoniccV d}d d}d "|tjz}dkr z  fd} tj||\} } | dkr | |}nAt| S#t$r%||r| |}||YdSwxYwm)aWait for a process PID to terminate. If the process terminated normally by calling exit(3) or _exit(2), or by returning from main(), the return value is the positive integer passed to *exit(). If it was terminated by a signal it returns the negated value of the signal which caused the termination (e.g. -SIGTERM). If PID is not a children of os.getpid() (current process) just wait until the process disappears and return None. If PID does not exist at all return None immediately. If timeout is specified and process is still alive raise TimeoutExpired. If timeout=0 either return immediately or raise TimeoutExpired (non-blocking). g-C6?g{Gz?rNcdkskrt||dzS)Nrr)interval_min_sleep_timer max_intervalstop_attimeouts rsleep_or_timeoutz(wait_pid_posix..sleep_or_timeoutsU a<= 5.3 + Python >= 3.9 only. rNzpidfd_open() failed (); use fallbacki)r pidfd_openOSErrorerrnoESRCHr@EMFILEENFILEENODEVrselectpollregisterPOLLINintrr<close)rr7pidfderrpoller timeout_mseventss rwait_pid_pidfd_openrVsW  c1%%     9 # #"#w// / / / / / / 9u|U\B B B @#@@@ A A A!#w// / / / / / /   v}---$_TT#gn2E2E Z(( * )) )W%% s: B$$BB$ A BB$BB$(A>D;;Ec( tj}nZ#t$rM}|jtjtjhvr(t d|dt||cYd}~Sd}~wwxYw tj|tj tj tj ztj } | |gd|}|st|t|||S#t$rl}|jtjtjtjhvrfflagsrzkqueue.control() failed ()rKkqueuerErFrHrIrr@keventKQ_FILTER_PROC KQ_EV_ADD KQ_EV_ONESHOT KQ_NOTE_EXITcontrolrr<rPEACCESEPERMrG)rr7kqrRkevrUs rwait_pid_kqueuerfs ]__  9u|4 4 4 z!can_use_kqueue..s,11awvq!!111111r FrXrrT)allrKr[r\rrir]r^r_r`rarPrErFrHrI)namesrdrerRs rcan_use_kqueuerqs_ E 115111 1 1u B ]__m IKK("V%99&     C5!Q > HHJJJJJ >  9u|4 4 4444 > HHJJJJJ >uuu > HHJJJJJ >  > HHJJJJ s0A?B;; D%D $D(D( D%%D((Ec|dksJ||dksJtrt||Strt||St ||S)Nr)rjrVrqrfr@)rr7s rr r (sp 7777!||||,"3000   ,sG,,,c7+++r c$tj|}|j|jz}|j|jz}|j|jz}||z }t rtj||}||z}t||d}tj ||||S)a.Return disk usage associated with path. Note: UNIX usually reserves 5% disk space which is not accessible by user. In this function "total" and "used" values reflect the total and used disk space whereas "free" and "percent" represent the "free" and "used percent" user disk space. r)round_)totalusedfreepercent) rstatvfsf_blocksf_frsizef_bfreef_bavailrr disk_usage_usedr ntp sdiskusage)pathstru avail_to_root avail_to_userrv total_userusage_percent_users rrr:s D  B K"+ %EJ,MK"+-M = D 7*466 %J'tZBBB >$] path as a dict. Used by Process.terminal(). z /dev/tty*z /dev/pts/*)globrstatst_rdevFileNotFoundError)retlsrs rrr^s C ;  $)L"9"9 9B3 )-C % & &     D  JsA A)(A)rm)&__doc__enumrFrrrKsignaltimerr_commonrrrr r r __all__r IntEnumSignalsrr$r,r:getattrminsleepr@r<rVrfrjrqr rrrr rrs@ ,+ ######"""""" G F F, DL;;FN;;;   B  Z 74di 0 0 :A1A1A1A1H ) ) )    F@  $  @ , , , ,")!!!H       r