U Ã|ýf XãG@sB dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z z ddl Z Wnek r„dZ YnXddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddlm'Z'ddlm(Z(ddlm)Z)ddlm*Z*dd lm+Z+dd!lm,Z,dd"lm-Z-dd#lm.Z.dd$lm/Z/dd%lm0Z0dd&lm1Z1dd'lm2Z2dd(lm3Z3dd)lm4Z4dd*lm5Z5dd+lm6Z6dd,lm7Z7dd-lm8Z8dd.lm9Z9dd/lm:Z:dd0lm;Z;dd1lmZ>dd4lm?Z?dd5lm@ZAdd6lBmCZDdd7lBmEZEdd8lBmFZFdd9lBmGZHdd:lBmIZIe rXd;ZJddlKmNZNdd?lKmOZOdd@lKmPZPne8rðddAlmQZLddBlRmSZSddClRmTZTddDlRmUZUddElRmVZVddFlRmWZWddGlRmXZXddHlQmYZYddIlQmZZZddJlQm[Z[ddKlQm\Z\ddLlQm]Z]n~e!rddMlm^ZLnjerddNlm_ZLnVe7rHddOlm`ZLddPl`maZaddQl`mbZbd;ZJn&er`ddRlmcZLd;ZJneddSe jeƒ‚dTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedddfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dd€dd‚dƒd„d…d†d‡dˆd‰dŠd‹dŒddŽddd‘d’d“d”d•d–d—d˜d™gGZfef geLjh¡eieLjjdšƒrrdd›lmkZkelƒZmdZneoekƒD]4Znen pdœ¡r8en q¡r8erekenƒemen<ef sen¡q8[m[neLjtZtdZudžZvewdŸd „ev xd¡¡DƒƒZyere d¢e j ƒZzda{da|e}ƒZ~eev €d¡d£¡ƒereLjd¤dƒkrRd¥eLjj‚Zƒeƒd¦7ZƒeieLjd¤ƒr eƒd§d¡ „d¨d „e…eLjj†ƒDƒ¡evf7Zƒn eƒd©ev7ZƒeƒdªereLjd«d¬ƒ7Zƒeƒd­7Zƒeeƒƒ‚eieLd®ƒrfeLj‡Zˆnd¯d°„Zˆd±d²„Z‰Gd³d„„d„e}ƒZjeŠd´d „eoejƒDƒƒZ‹Gdµd…„d…ejƒZŒd¶d‡„Zd·d†„ZŽiaeŠƒZdíd¸dˆ„Z‘d¹dº„e‘_’d»e‘j’_dîd¼d‰„Z“dïd¾d„Z”dðdÀdŒ„Z•ze  –¡j—e•ƒiZ˜Wne™k r.iZ˜YnXze  –¡j—e•d½dÁiZšWne™k rbiZšYnXdÂdÄZ›dÄdÅ„ZœdÆdÇ„ZdñdÈd„Zže˜ Ÿ¡Z eš Ÿ¡Z¡dòdÉdŽ„Z¢dÊd„Z£eieLd˃rÈdódÌdË„Z¤ef sdË¡eied̓sàeieLd̓reied̓rôej¥Z¥neLj¥Z¥ef sdÍ¡dÎdŠ„Z¦dÏd‹„Z§dÐd—„Z¨dôdÑd–„Z©dõdÒd•„Zªe «eAj’dÓ¡eª_’dÔeªj’_dödÕd‘„Z¬e «eAj’dÖ¡e¬_’dÔe¬j’_d÷dØd’„Z­dÙd“„Z®dÚd”„Z¯eieLdÛƒr¤dødÜdÛ„Z°ef sdÛ¡eieLd݃rÂdÞdÝ„Z±ef sdÝ¡eieLd߃ràdàdß„Z²ef sdß¡dád™„Z³dâd˜„Z´e8 rdãdä„Zµdådæ„Z¶dçdè„Z·dédê„Z¸[?[e jyddëk r.[¹[ºe»dìk r>e¸ƒdS)ùa/psutil is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. Supported platforms: - Linux - Windows - macOS - FreeBSD - OpenBSD - NetBSD - Sun Solaris - AIX Works with Python versions 2.7 and 3.6+. é)ÚdivisionNé)Ú_common)ÚAIX)ÚBSD)Ú CONN_CLOSE)ÚCONN_CLOSE_WAIT)Ú CONN_CLOSING)ÚCONN_ESTABLISHED)ÚCONN_FIN_WAIT1)ÚCONN_FIN_WAIT2)Ú CONN_LAST_ACK)Ú CONN_LISTEN)Ú CONN_NONE)Ú CONN_SYN_RECV)Ú CONN_SYN_SENT)ÚCONN_TIME_WAIT)ÚFREEBSD)ÚLINUX)ÚMACOS)ÚNETBSD)ÚNIC_DUPLEX_FULL)ÚNIC_DUPLEX_HALF)ÚNIC_DUPLEX_UNKNOWN)ÚOPENBSD)ÚOSX)ÚPOSIX)ÚPOWER_TIME_UNKNOWN)ÚPOWER_TIME_UNLIMITED)Ú STATUS_DEAD)ÚSTATUS_DISK_SLEEP)Ú STATUS_IDLE)Ú STATUS_LOCKED)Ú STATUS_PARKED)ÚSTATUS_RUNNING)ÚSTATUS_SLEEPING)ÚSTATUS_STOPPED)ÚSTATUS_TRACING_STOP)ÚSTATUS_WAITING)Ú STATUS_WAKING)Ú STATUS_ZOMBIE)ÚSUNOS)ÚWINDOWS)Ú AccessDenied)ÚError)Ú NoSuchProcess)ÚTimeoutExpired)Ú ZombieProcess)Údebug)Úmemoize_when_activated)Ú wrap_numbers)ÚPY3)ÚPermissionError)ÚProcessLookupError)ÚSubprocessTimeoutExpired)Úlongz/proc)Ú_pslinux)ÚIOPRIO_CLASS_BE)ÚIOPRIO_CLASS_IDLE)ÚIOPRIO_CLASS_NONE)ÚIOPRIO_CLASS_RT)Ú _pswindows)ÚABOVE_NORMAL_PRIORITY_CLASS)ÚBELOW_NORMAL_PRIORITY_CLASS)ÚHIGH_PRIORITY_CLASS)ÚIDLE_PRIORITY_CLASS)ÚNORMAL_PRIORITY_CLASS)ÚREALTIME_PRIORITY_CLASS)ÚCONN_DELETE_TCB)Ú IOPRIO_HIGH)Ú IOPRIO_LOW)Ú IOPRIO_NORMAL)ÚIOPRIO_VERYLOW)Ú_psosx)Ú_psbsd)Ú_pssunos)Ú CONN_BOUND)Ú CONN_IDLE)Ú_psaixzplatform %s is not supportedr.r/r1r-r0Ú version_infoÚ __version__r$r!r%r r&r'r*rr)r"r(r#r rrr r rrrr rr rÚAF_LINKrrrrrrrrrrrrrr+r,rÚProcessÚPopenÚ pid_existsÚpidsÚ process_iterÚ wait_procsÚvirtual_memoryÚ swap_memoryÚ cpu_timesÚ cpu_percentÚcpu_times_percentÚ cpu_countÚ cpu_statsÚnet_io_countersÚnet_connectionsÚ net_if_addrsÚ net_if_statsÚdisk_io_countersÚdisk_partitionsÚ disk_usageÚusersÚ boot_timeÚrlimit)Ú _psutil_posixZRLIMzGiampaolo Rodola'z6.0.0cCsg|] }t|ƒ‘qS©)Úint)Ú.0ÚnumrlrlúB/opt/alt/python38/lib64/python3.8/site-packages/psutil/__init__.pyÚ ÚsrqÚ.Ú monotonicÚÚversionz!version conflict: %r C extension z.module was built for another version of psutilz (%s instead of %s)cCsg|]}|‘qSrlrl©rnÚxrlrlrprqîsz (different than %s)z;; you may try to 'pip uninstall psutil', manually remove %sÚ__file__z%the existing psutil install directoryz1 or clean the virtual env somehow, then reinstallÚppid_mapc CsDi}tƒD]4}zt |¡ ¡||<Wq ttfk r<Yq Xq |S)z{Return a {pid: ppid, ...} dict for all running processes in one shot. Used to speed up Process.children(). )rWÚ _psplatformrTÚppidr/r1)ÚretÚpidrlrlrpÚ _ppid_maps r~cCs6t ¡}t||ƒ}|dkr dnd}tj |¡ |¡S)z(Format seconds in a human readable form.i€Qz%H:%M:%Sz%Y-%m-%d %H:%M:%S)ÚtimermÚdatetimeÚ fromtimestampÚstrftime)ZsecsÚnowZsecs_agoÚfmtrlrlrpÚ _pprint_secss r…c@s”eZdZdZd~dd„Zddd„Zdd „ZeZd d „Zd d „Z dd„Z dd„Z e dd„ƒZ ejdd„ƒZd€dd„Zdd„Zdd„Zdd„Zedd„ƒZd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zdd.d/„Zered0d1„ƒZ d2d3„Z!d4d5„Z"d6d7„Z#e$e%j&d8ƒrd9d:„Z'e$e%j&d;ƒr.d‚dƒrFdƒd?d@„Z)e$e%j&dAƒr^d„dBdC„Z*e$e%j&dDƒrtdEdF„Z+e$e%j&dGƒrŠdHdI„Z,e-r˜dJdK„Z.dLdM„Z/dNdO„Z0e$e%j&dPƒr¾dQdR„Z1d…dSdT„Z2d†dUdV„Z3edWdX„ƒZ4edYdZ„ƒZ5e6j7d[d\d]d^„ƒZ8d_d`„Z9d‡dbdc„Z:e$e%j&ddƒr(dˆdfdg„Z;dhdi„Zer^dpdq„Z?drds„Z@dtdu„ZAdvdw„ZBdxdy„ZCdzd{„ZDd‹d|d}„ZEdS)ŒrTaRepresents an OS process with the given PID. If PID is omitted current process PID (os.getpid()) is used. Raise NoSuchProcess if PID does not exist. Note that most of the methods of this class do not make sure that the PID of the process being queried has been reused. That means that you may end up retrieving information for another process. The only exceptions for which process identity is pre-emptively checked and guaranteed are: - parent() - children() - nice() (set) - ionice() (set) - rlimit() (set) - cpu_affinity (set) - suspend() - resume() - send_signal() - terminate() - kill() To prevent this problem for all other methods you can use is_running() before querying the process. NcCs| |¡dS©N)Ú_init)Úselfr}rlrlrpÚ__init__>szProcess.__init__FcCsX|dkrt ¡}ntts4t|ttfƒs4d|}t|ƒ‚|dkrLd|}t|ƒ‚ztj   |¡Wn(t k r„d|}t ||d‚YnX||_ d|_d|_d|_d|_d|_d|_t ¡|_d|_t |¡|_d|_d|_t|_z | ¡WnZtk rþYnHt k rYn4t k rD|s:d}t ||d‚nd|_YnX|j!|jf|_"dS) Nzpid must be an integer (got %r)rz'pid must be a positive integer (got %s)z!process PID out of range (got %s)©ÚmsgFzprocess PID not foundT)#ÚosÚgetpidÚ_PY3Ú isinstancermr9Ú TypeErrorÚ ValueErrorrzÚcextZcheck_pid_rangeÚ OverflowErrorr/Ú_pidÚ_nameÚ_exeÚ _create_timeÚ_goneÚ _pid_reusedÚ_hashÚ threadingÚRLockÚ_lockÚ_ppidrTÚ_procÚ_last_sys_cpu_timesÚ_last_proc_cpu_timesÚ _SENTINELÚ _exitcodeÚ create_timer-r1r}Ú_ident)rˆr}Ú _ignore_nspr‹rlrlrpr‡AsL     z Process._initc Cst ¡}|j|d<|jr"|j|d<| ¡Þ|jr.)Ú collectionsÚ OrderedDictr}r•Úoneshotr™r§r¨r1r/r-r£r¢r—r…Ú __class__Ú __module__Ú__name__ÚjoinÚitems)rˆÚinforlrlrpÚ__str__ys2         ýzProcess.__str__cCsjt|tƒstStstr^|j\}}|j\}}||kr^|r^|s^z| ¡tkWStk r\YnX|j|jkSr†) rrTÚNotImplementedrrr¥r¨r*r.)rˆÚotherZpid1Zctime1Zpid2Zctime2rlrlrpÚ__eq__™s   zProcess.__eq__cCs ||k Sr†rl)rˆrºrlrlrpÚ__ne__®szProcess.__ne__cCs|jdkrt|jƒ|_|jSr†)ršÚhashr¥©rˆrlrlrpÚ__hash__±s  zProcess.__hash__cCs.|js| ¡s*|jr*d}t|j|j|d‚dS)z9Raises NoSuchProcess in case process PID has been reused.z4process no longer exists and its PID has been reusedrŠN)r™Ú is_runningr/r}r•)rˆr‹rlrlrpÚ_raise_if_pid_reused¶szProcess._raise_if_pid_reusedcCs|jS)zThe process PID.)r”r¾rlrlrpr}Âsz Process.pidc cs²|j¢t|dƒrdVnŠzH|j  |¡|j  |¡|j  |¡trP|j  |¡|j  ¡dVW5|j |¡|j |¡|j |¡tr˜|j |¡|j  ¡XW5QRXdS)a#Utility context manager which considerably speeds up the retrieval of multiple process information at the same time. Internally different process info (e.g. name, ppid, uids, gids, ...) may be fetched by using the same routine, but only one information is returned and the others are discarded. When using this context manager the internal routine is executed once (in the example below on name()) and the other info are cached. The cache is cleared when exiting the context manager block. The advice is to use this every time you retrieve more than one information about the process. If you're lucky, you'll get a hell of a speedup. >>> import psutil >>> p = psutil.Process() >>> with p.oneshot(): ... p.name() # collect multiple info ... p.cpu_times() # return cached value ... p.cpu_percent() # return cached value ... p.create_time() # return cached value ... >>> Ú_cacheN) rÚhasattrr\Zcache_deactivateÚ memory_infor{rÚuidsrŸZ oneshot_exitZcache_activateZ oneshot_enterr¾rlrlrpr±És"           zProcess.oneshotc Cs t}|dk rvt|ttttfƒs2dt|ƒ}t|ƒ‚t|ƒ}||}|rvdt|ƒdkrXdndd  t t |ƒ¡f}t |ƒ‚i}|p€|}|  ¡v|D]j}z$|dkr¦|j} nt||ƒ} | ƒ} Wn8ttfk rÔ|} Yntk rð|rè‚YqYnX| ||<qW5QRX|S) aäUtility method returning process information as a hashable dictionary. If *attrs* is specified it must be a list of strings reflecting available Process class' attribute names (e.g. ['cpu_times', 'name']) else all public (read only) attributes are assumed. *ad_value* is the value which gets assigned in case AccessDenied or ZombieProcess exception is raised when retrieving that particular process information. Nzinvalid attrs type %szinvalid attr name%s %srÚsrtr¬r})Ú_as_dict_attrnamesrÚlistÚtupleÚsetÚ frozensetÚtyperÚlenrµÚmapÚreprr‘r±r}Úgetattrr-r1ÚNotImplementedError) rˆÚattrsÚad_valueZ valid_namesr‹Ú invalid_namesZretdictÚlsr§r|ÚmethrlrlrpÚas_dict s<  þ    zProcess.as_dictcCsttdk r tntƒd}|j|kr$dS| ¡}|dk rp| ¡}zt|ƒ}| ¡|krX|WSWntk rnYnXdS)zReturn the parent process as a Process object pre-emptively checking whether PID has been reused. If no parent is known return None. Nr)Ú _LOWEST_PIDrWr}r{r¤rTr/)rˆZ lowest_pidr{ÚctimeÚparentrlrlrprÚ;s   zProcess.parentcCs,g}| ¡}|dk r(| |¡| ¡}q |S)zReturn the parents of this process as a list of Process instances. If no parents are known return an empty list. N)rÚÚappend)rˆÚparentsÚprocrlrlrprÜNs   zProcess.parentscCsx|js |jrdSz2|t|jƒk|_|jr>t |j¡t|jƒ‚WdStk rXYdStk rrd|_YdSXdS)zãReturn whether this process is running. It also checks if PID has been reused by another process, in which case it will remove the process from `process_iter()` internal cache and return False. FTN)r˜r™rTr}Ú _pids_reusedÚaddr/r1r¾rlrlrprÀYs   zProcess.is_runningcCs2| ¡tr|j ¡S|jp$|j ¡|_|jSdS)z`The process parent PID. On Windows the return value is cached after first call. N)rÁrrŸr{ržr¾rlrlrpr{vs  z Process.ppidc Csˆtr|jdk r|jS|j ¡}trvt|ƒdkrvz | ¡}Wnttfk rRYn$X|rvt j   |d¡}|  |¡rv|}||_||j_|S)z>The process name. The return value is cached after first call.Nér) r,r•rŸr§rrÍÚcmdliner-r1rŒÚpathÚbasenameÚ startswith)rˆr§ráZ extended_namerlrlrpr§‰s   z Process.namec sЇfdd„}ˆjdkr„zˆj ¡}Wn0tk rT}z||dWY¢Sd}~XYn0X|s~z||d}Wntk r|YnX|ˆ_ˆjS)zŽThe process executable as an absolute path. May also be an empty string. The return value is cached after first call. csdˆ ¡}|rRttdƒrRttdƒrR|d}tj |¡rRtj |¡rRt |tj¡rR|St|t ƒr`|‚|S)NÚaccessÚX_OKr) rárÃrŒrâÚisabsÚisfilerårærr-)ÚfallbackráÚexer¾rlrpÚguess_it®s ÿ þ ý zProcess.exe..guess_itN)ré)r–rŸrêr-)rˆrërêÚerrrlr¾rprê¨s   z Process.execCs |j ¡S)z3The command line this process has been called with.)rŸrár¾rlrlrpráÒszProcess.cmdlinecCs*z |j ¡WStk r$tYSXdS)z2The process current status as a STATUS_* constant.N)rŸr¨r1r*r¾rlrlrpr¨Ös zProcess.statuscCs^trPtdkrd}t|ƒ‚| ¡j}zt |¡jWStk rLt|ƒYSXn |j   ¡SdS)ztThe name of the user that owns the process. On UNIX this is calculated by using *real* process uid. Nz0requires pwd module shipped with standard python) rÚpwdÚ ImportErrorrÅÚrealÚgetpwuidÚpw_nameÚKeyErrorÚstrrŸÚusername)rˆr‹Zreal_uidrlrlrprôÝs zProcess.usernamecCs|jdkr|j ¡|_|jS)z The process creation time as a floating point number expressed in seconds since the epoch. The return value is cached after first call. N)r—rŸr¤r¾rlrlrpr¤ïs  zProcess.create_timecCs |j ¡S)z6Process current working directory as an absolute path.)rŸÚcwdr¾rlrlrprõøsz Process.cwdcCs*|dkr|j ¡S| ¡|j |¡dS)z'Get or set process niceness (priority).N)rŸZnice_getrÁZnice_set)rˆÚvaluerlrlrpÚniceüs z Process.nicecCs |j ¡S)zVReturn process UIDs as a (real, effective, saved) namedtuple. )rŸrÅr¾rlrlrprÅsz Process.uidscCs |j ¡S)zVReturn process GIDs as a (real, effective, saved) namedtuple. )rŸÚgidsr¾rlrlrprø sz Process.gidscCs |j ¡S)zVThe terminal associated with this process, if any, else None. )rŸÚterminalr¾rlrlrprùszProcess.terminalcCs |j ¡S)zcReturn the number of file descriptors opened by this process (POSIX only). )rŸÚnum_fdsr¾rlrlrprúszProcess.num_fdsÚ io_counterscCs |j ¡S)a Return process I/O statistics as a (read_count, write_count, read_bytes, write_bytes) namedtuple. Those are the number of read/write calls performed and the amount of bytes read and written by the process. )rŸrûr¾rlrlrprû"szProcess.io_countersÚ ionice_getcCs@|dkr&|dk rd}t|ƒ‚|j ¡S| ¡|j ||¡SdS)a´Get or set process I/O niceness (priority). On Linux *ioclass* is one of the IOPRIO_CLASS_* constants. *value* is a number which goes from 0 to 7. The higher the value, the lower the I/O priority of the process. On Windows only *ioclass* is used and it can be set to 2 (normal), 1 (low) or 0 (very low). Available on Linux and Windows > Vista only. Nz$'ioclass' argument must be specified)r‘rŸrürÁZ ionice_set)rˆZioclassrör‹rlrlrpÚionice.s  zProcess.ionicerjcCs|dk r| ¡|j ||¡S)a-Get or set process resource limits as a (soft, hard) tuple. *resource* is one of the RLIMIT_* constants. *limits* is supposed to be a (soft, hard) tuple. See "man prlimit" for further info. Available on Linux and FreeBSD only. N)rÁrŸrj)rˆÚresourceZlimitsrlrlrprjFs zProcess.rlimitÚcpu_affinity_getcCsl|dkrtt|j ¡ƒƒS| ¡|sTt|jdƒr>|j ¡}nttt t ddƒƒƒ}|j  t t|ƒƒ¡dS)a-Get or set process CPU affinity. If specified, *cpus* must be a list of CPUs for which you want to set the affinity (e.g. [0, 1]). If an empty list is passed, all egible CPUs are assumed (and set). (Windows, Linux and BSD only). NÚ_get_eligible_cpusT©Úpercpu) ÚsortedrÊrŸrÿrÁrÃrrÉÚrangerÍr\Zcpu_affinity_setrÈ)rˆZcpusrlrlrpÚ cpu_affinityWs  zProcess.cpu_affinityÚcpu_numcCs |j ¡S)aZReturn what CPU this process is currently running on. The returned number should be <= psutil.cpu_count() and <= len(psutil.cpu_percent(percpu=True)). It may be used in conjunction with psutil.cpu_percent(percpu=True) to observe the system workload distributed across CPUs. )rŸrr¾rlrlrprmszProcess.cpu_numÚenvironcCs |j ¡S)z’The environment variables of the process as a dict. Note: this might not reflect changes made after the process started. )rŸrr¾rlrlrprzszProcess.environcCs |j ¡S)z\Return the number of handles opened by this process (Windows only). )rŸÚ num_handlesr¾rlrlrpr‚szProcess.num_handlescCs |j ¡S)zkReturn the number of voluntary and involuntary context switches performed by this process. )rŸÚnum_ctx_switchesr¾rlrlrpr ˆszProcess.num_ctx_switchescCs |j ¡S)z2Return the number of threads used by this process.)rŸÚ num_threadsr¾rlrlrpr ŽszProcess.num_threadsÚthreadscCs |j ¡S)zïReturn threads opened by process as a list of (id, user_time, system_time) namedtuples representing thread id and thread CPU times (user/system). On OpenBSD this method requires root access. )rŸr r¾rlrlrpr ”szProcess.threadsc Cs4| ¡tƒ}g}|st| ¡D]R\}}||jkrz&t|ƒ}| ¡| ¡krT| |¡Wqttfk rnYqXqn¼t   t ¡}| ¡D]\}}|| |¡q†t ƒ}|jg} | r0|   ¡}||krÄq¬| |¡||D]V} z6t| ƒ}| ¡| ¡k} | r| |¡|  | ¡WqÖttfk r*YqÖXqÖq¬|S)u(Return the children of this process as a list of Process instances, pre-emptively checking whether PID has been reused. If *recursive* is True return all the parent descendants. Example (A == this process): A ─┠│ ├─ B (child) ─┠│ └─ X (grandchild) ─┠│ └─ Y (great grandchild) ├─ C (child) └─ D (child) >>> import psutil >>> p = psutil.Process() >>> p.children() B, C, D >>> p.children(recursive=True) B, X, Y, C, D Note that in the example above if process X disappears process Y won't be listed as the reference to process A is lost. )rÁr~r¶r}rTr¤rÛr/r1r¯Ú defaultdictrÈrÊÚpoprß) rˆÚ recursiveryr|r}r{ÚchildZreverse_ppid_mapÚseenÚstackZ child_pidZintimerlrlrpÚchildrenœs@       zProcess.childrenc s|dk o|dk}|dk r0|dkr0d|}t|ƒ‚tƒp8d‰‡fdd„}|rv|ƒ}|j ¡}t |¡|ƒ}|j ¡}n<|j}|j}|ƒ}|j ¡}|dks¢|dkr²||_||_dS|j|j|j |j } ||} ||_||_z| | d} Wnt k rYdSX| ˆ} t | dƒSdS) aReturn a float representing the current process CPU utilization as a percentage. When *interval* is 0.0 or None (default) compares process times to system CPU times elapsed since last call, returning immediately (non-blocking). That means that the first time this is called it will return a meaningful 0.0 value. When *interval* is > 0.0 compares process times to system CPU times elapsed before and after the interval (blocking). In this case is recommended for accuracy that this function be called with at least 0.1 seconds between calls. A value > 100.0 can be returned in case of processes running multiple threads on different CPU cores. The returned value is explicitly NOT split evenly between all available logical CPUs. This means that a busy loop process running on a system with 2 logical CPUs will be reported as having 100% CPU utilization instead of 50%. Examples: >>> import psutil >>> p = psutil.Process(os.getpid()) >>> # blocking >>> p.cpu_percent(interval=1) 2.0 >>> # non-blocking (percentage since last call) >>> p.cpu_percent(interval=None) 2.9 >>> Nçrú!interval is not positive (got %r)rcs tƒˆSr†)Ú_timerrl©Únum_cpusrlrpÚtimer sz"Process.cpu_percent..timeréd) r‘r_rŸr\rÚsleepr r¡ÚuserÚsystemÚZeroDivisionErrorÚround) rˆÚintervalÚblockingr‹rZst1Zpt1Zst2Zpt2Z delta_procZ delta_timeZoverall_cpus_percentZsingle_cpu_percentrlrrpr]âs<#      zProcess.cpu_percentcCs |j ¡S)a%Return a (user, system, children_user, children_system) namedtuple representing the accumulated process time, in seconds. This is similar to os.times() but per-process. On macOS and Windows children_user and children_system are always set to 0. )rŸr\r¾rlrlrpr\?s zProcess.cpu_timescCs |j ¡S)aReturn a namedtuple with variable fields depending on the platform, representing memory information about the process. The "portable" fields available on all platforms are `rss` and `vms`. All numbers are expressed in bytes. )rŸrÄr¾rlrlrprÄJs zProcess.memory_inforÄ)Ú replacementcCs| ¡Sr†)rÄr¾rlrlrpÚmemory_info_exUszProcess.memory_info_excCs |j ¡S)a]This method returns the same information as memory_info(), plus, on some platform (Linux, macOS, Windows), also provides additional metrics (USS, PSS and swap). The additional metrics provide a better representation of actual process memory usage. Namely USS is the memory which is unique to a process and which would be freed if the process was terminated right now. It does so by passing through the whole process address. As such it usually requires higher user privileges than memory_info() and is considerably slower. )rŸÚmemory_full_infor¾rlrlrpr#YszProcess.memory_full_infoÚrsscCsˆttjjƒ}||kr,d|t|ƒf}t|ƒ‚|tjjkr>|jn|j}|ƒ}t ||ƒ}t p^t ƒj }|dksxd|}t|ƒ‚|t |ƒdS)aÏCompare process memory to total physical system memory and calculate process memory utilization as a percentage. *memtype* argument is a string that dictates what type of process memory you want to compare against (defaults to "rss"). The list of available strings can be obtained like this: >>> psutil.Process().memory_info()._fields ('rss', 'vms', 'shared', 'text', 'lib', 'data', 'dirty', 'uss', 'pss') z&invalid memtype %r; valid types are %rrz`can't calculate process memory percent because total physical system memory is not positive (%r)r)rÈrzZpfullmemÚ_fieldsrÉr‘ZpmemrÄr#rÐÚ _TOTAL_PHYMEMrZÚtotalÚfloat)rˆZmemtypeZ valid_typesr‹ZfunZmetricsröZ total_phymemrlrlrpÚmemory_percentis* þ ÿý  ÿÿzProcess.memory_percentÚ memory_mapsTc s |j ¡}|r„i‰|D]R}|d}|dd…}ztdd„ˆ||ƒˆ|<Wqtk rf|ˆ|<YqXqtj‰‡‡fdd„ˆDƒStj‰‡fdd„|DƒSdS) aüReturn process' mapped memory regions as a list of namedtuples whose fields are variable depending on the platform. If *grouped* is True the mapped regions with the same 'path' are grouped together and the different memory fields are summed. If *grouped* is False every mapped region is shown as a single entity and the namedtuple will also include the mapped region's address space ('addr') and permission set ('perms'). ééNcSs||Sr†rl)rwÚyrlrlrpÚ¡óz%Process.memory_maps..csg|]}ˆ|fˆ|žŽ‘qSrlrl)rnrâ©ÚdÚntrlrprq¥sz'Process.memory_maps..csg|] }ˆ|Ž‘qSrlrlrv)r2rlrprq¨s)rŸr*rÎròrzZ pmmap_groupedZ pmmap_ext)rˆÚgroupedÚitZtuplrâÚnumsrlr0rpr*s  zProcess.memory_mapscCs |j ¡S)z˜Return files opened by process as a list of (path, fd) namedtuples including the absolute file name and file descriptor number. )rŸÚ open_filesr¾rlrlrpr6ªszProcess.open_filesÚinetcCs |j |¡S)aTReturn socket connections opened by process as a list of (fd, family, type, laddr, raddr, status) namedtuples. The *kind* parameter filters for connections that match the following criteria: +------------+----------------------------------------------------+ | Kind Value | Connections using | +------------+----------------------------------------------------+ | inet | IPv4 and IPv6 | | inet4 | IPv4 | | inet6 | IPv6 | | tcp | TCP | | tcp4 | TCP over IPv4 | | tcp6 | TCP over IPv6 | | udp | UDP | | udp4 | UDP over IPv4 | | udp6 | UDP over IPv6 | | unix | UNIX socket (both UDP and TCP protocols) | | all | the sum of all the possible families and protocols | +------------+----------------------------------------------------+ )rŸrb©rˆÚkindrlrlrprb±szProcess.net_connectionsrbcCs |j|dS)N©r9)rbr8rlrlrpÚ connectionsÉszProcess.connectionscCs´|jdkrt|jƒ‚| ¡|jdkr2d}t|ƒ‚zt |j|¡Wnjtk rŽtrvt|jƒrvt |j|j |j ƒ‚nd|_ t |j|j ƒ‚Yn"tk r®t|j|j ƒ‚YnXdS)Nrz›preventing sending signal to process with PID 0 as it would affect every process in the process group of the calling process (os.getpid()) instead of PID 0T)r}ÚAssertionErrorrÁr‘rŒÚkillr7rrVr1r•ržr˜r/r6r-©rˆÚsigr‹rlrlrpÚ _send_signalÑs ÿzProcess._send_signalcCsPtr| |¡n<| ¡|tjkr@| ¡s@d}t|j|j|d‚|j   |¡dS)zÚSend a signal *sig* to process pre-emptively checking whether PID has been reused (see signal module constants) . On Windows only SIGTERM is valid and is treated as an alias for kill(). zprocess no longer existsrŠN) rr@rÁÚsignalÚSIGTERMrÀr/r}r•rŸÚ send_signalr>rlrlrprCés zProcess.send_signalcCs(tr| tj¡n| ¡|j ¡dS)zµSuspend process execution with SIGSTOP pre-emptively checking whether PID has been reused. On Windows this has the effect of suspending all process threads. N)rr@rAÚSIGSTOPrÁrŸÚsuspendr¾rlrlrprEøszProcess.suspendcCs(tr| tj¡n| ¡|j ¡dS)z²Resume process execution with SIGCONT pre-emptively checking whether PID has been reused. On Windows this has the effect of resuming all process threads. N)rr@rAÚSIGCONTrÁrŸÚresumer¾rlrlrprGszProcess.resumecCs(tr| tj¡n| ¡|j ¡dS)z—Terminate the process with SIGTERM pre-emptively checking whether PID has been reused. On Windows this is an alias for kill(). N)rr@rArBrÁrŸr=r¾rlrlrpÚ terminateszProcess.terminatecCs(tr| tj¡n| ¡|j ¡dS)zjKill the current process with SIGKILL pre-emptively checking whether PID has been reused. N)rr@rAÚSIGKILLrÁrŸr=r¾rlrlrpr=sz Process.killcCs@|dk r|dksd}t|ƒ‚|jtk r,|jS|j |¡|_|jS)aôWait for process to terminate and, if process is a children of os.getpid(), also return its exit code, else None. On Windows there's no such limitation (exit code is always returned). If the process is already terminated immediately return None instead of raising NoSuchProcess. If *timeout* (in seconds) is specified and process is still alive raise TimeoutExpired. To wait for multiple Process(es) use psutil.wait_procs(). Nrz"timeout must be a positive integer)r‘r£r¢rŸÚwait)rˆÚtimeoutr‹rlrlrprJ#s z Process.wait)N)F)NN)N)NN)N)N)F)N)r$)T)r7)r7)N)Fr´r³Ú __qualname__Ú__doc__r‰r‡r¸Ú__repr__r»r¼r¿rÁÚpropertyr}Ú contextlibÚcontextmanagerr±r×rÚrÜrÀr3r{r§rêrár¨rôr¤rõr÷rrÅrørùrúrÃrzrTrûrýrjrrrr,rr r r rr]r\rÄrZdeprecated_methodr"r#r)r*r6rbr;r@rCrErGrHr=rJrlrlrlrprT"s–  8   B /  *         F ]    $        cCs"g|]}| d¡s|dkr|‘qS)Ú_>rHr×rGr=rCrrÜr;rÚrErÀr±r"rjrJ)rärvrlrlrprq=s  ÿcsJeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd‡fd d„ Z ‡Z S)rUaSame as subprocess.Popen, but in addition it provides all psutil.Process methods in a single class. For the following methods which are common to both classes, psutil implementation takes precedence: * send_signal() * terminate() * kill() This is done in order to avoid killing another process in case its PID has been reused, fixing BPO-6973. >>> import psutil >>> from subprocess import PIPE >>> p = psutil.Popen(["python", "-c", "print 'hi'"], stdout=PIPE) >>> p.name() 'python' >>> p.uids() user(real=1000, effective=1000, saved=1000) >>> p.username() 'giampaolo' >>> p.communicate() ('hi', None) >>> p.terminate() >>> p.wait(timeout=2) 0 >>> cOs$tj||Ž|_|j|jjdddS)NT)r¦)Ú subprocessrUÚ_Popen__subprocr‡r}©rˆÚargsÚkwargsrlrlrpr‰gszPopen.__init__cCsttttƒttjƒƒƒSr†)rrÊÚdirrUrSr¾rlrlrpÚ__dir__nsz Popen.__dir__cCst|jdƒr|j ¡|S)NÚ __enter__)rÃrTrZr¾rlrlrprZqs  zPopen.__enter__cOs^t|jdƒr|jj||ŽS|jr*|j ¡|jr:|j ¡z|jrL|j ¡W5| ¡XdS)NÚ__exit__)rÃrTr[ÚstdoutÚcloseÚstderrrJÚstdinrUrlrlrpr[vs   zPopen.__exit__c Csjzt ||¡WStk rdzt |j|¡WYStk r^d|jj|f}t|ƒ‚YnXYnXdS)Nz!%s instance has no attribute '%s')ÚobjectÚ__getattribute__ÚAttributeErrorrTr²r´)rˆr§r‹rlrlrpra†sþzPopen.__getattribute__Ncs0|jjdk r|jjStt|ƒ |¡}||j_|Sr†)rTÚ returncodeÚsuperrUrJ)rˆrKr|©r²rlrprJ“s  z Popen.wait)N) r´r³rLrMr‰rYrZr[rarJÚ __classcell__rlrlrerprUIs cCstt ¡ƒ}|da|S)z&Return a list of current running PIDs.r)rrzrWrØ©r|rlrlrprW s cCs0|dkr dS|dkr"tr"|tƒkSt |¡SdS)z“Return True if given PID exists in the current process list. This is faster than doing "pid in psutil.pids()" and should be preferred. rFN)rrWrzrV©r}rlrlrprV¨s   c #s ‡fdd„}‡fdd„}t ¡‰ttƒƒ}tˆ ¡ƒ}||}||}|D] }||ƒqJtrzt ¡}td|ƒ||ƒqXz„tt ˆ  ¡ƒt t   |¡  ¡ƒƒ} | D]X\}} z2| dkr¼||ƒ} |dk rÔ| j ||d| _| VWq¢tk rø||ƒYq¢Xq¢W5ˆaXdS)a£Return a generator yielding a Process instance for all running processes. Every new Process instance is only created once and then cached into an internal table which is updated every time this is used. Cache can optionally be cleared via `process_iter.clear_cache()`. The sorting order in which processes are yielded is based on their PIDs. *attrs* and *ad_value* have the same meaning as in Process.as_dict(). If *attrs* is specified as_dict() is called and the resulting dict is stored as a 'info' attribute attached to returned Process instance. If *attrs* is an empty list it will retrieve all process info (slow). cst|ƒ}|ˆ|j<|Sr†)rTr})r}rÝ©ZpmaprlrprßÒs zprocess_iter..addcsˆ |d¡dSr†)r rhrirlrpÚremove×szprocess_iter..removez-refreshing Process instance for reused PID %sN)rÒrÓ)Ú_pmapÚcopyrÊrWÚkeysrÞr r2rrÈr¶ÚdictÚfromkeysr×r·r/) rÒrÓrßrjÚaÚbZnew_pidsZ gone_pidsr}rÕrÝrlrirprX¾s2       "  cCst ¡Sr†)rkÚclearrlrlrlrpr.ôr/r.z$Clear process_iter() internal cache.c s‡‡fdd„}|dk r.|dks.d|}t|ƒ‚tƒ‰t|ƒ}ˆdk r\tˆƒs\dˆ}t|ƒ‚|dk rntƒ|}|rÞ|dk r„|dkr„qÞ|D]J}dt|ƒ}|dk rÈt|tƒ|ƒ}|dkr¼qÔ|||ƒqˆ|||ƒqˆ|ˆ}qn|rþ|D]}||dƒqæ|ˆ}tˆƒt|ƒfS)a,Convenience function which waits for a list of processes to terminate. Return a (gone, alive) tuple indicating which processes are gone and which ones are still alive. The gone ones will have a new *returncode* attribute indicating process exit status (may be None). *callback* is a function which gets called every time a process terminates (a Process instance is passed as callback argument). Function will return as soon as all processes terminate or when *timeout* occurs. Differently from Process.wait() it will not raise TimeoutExpired if *timeout* occurs. Typical use case is: - send SIGTERM to a list of processes - give them some time to terminate - send SIGKILL to those ones which are still alive Example: >>> def on_terminate(proc): ... print("process {} terminated".format(proc)) ... >>> for p in procs: ... p.terminate() ... >>> gone, alive = wait_procs(procs, timeout=3, callback=on_terminate) >>> for p in alive: ... p.kill() cslz|j|d}Wn&tk r$YnDtk r6Yn2X|dk sH| ¡sh||_ˆ |¡ˆdk rhˆ|ƒdS)N)rK)rJr0Ú_SubprocessTimeoutExpiredrÀrcrß)rÝrKrc©ÚcallbackÚgonerlrpÚ check_gones zwait_procs..check_goneNrz*timeout must be a positive integer, got %szcallback %r is not a callablegð?)r‘rÊÚcallablerrrÍÚminrÈ) ZprocsrKrurwr‹ÚaliveÚdeadlinerÝZ max_timeoutrlrtrprYøs8%      TcCs.|rt ¡}nt ¡}|dk r*|dkr*d}|S)azReturn the number of logical CPUs in the system (same as os.cpu_count() in Python 3.4). If *logical* is False return the number of physical cores only (e.g. hyper thread CPUs are excluded). Return None if undetermined. The return value is cached after first call. If desired cache can be cleared like this: >>> psutil.cpu_count.cache_clear() Nr)rzZcpu_count_logicalZcpu_count_cores)Zlogicalr|rlrlrpr_Zs  FcCs|s t ¡St ¡SdS)aReturn system-wide CPU times as a namedtuple. Every CPU time represents the seconds the CPU has spent in the given mode. The namedtuple's fields availability varies depending on the platform: - user - system - idle - nice (UNIX) - iowait (Linux) - irq (Linux, FreeBSD) - softirq (Linux) - steal (Linux >= 2.6.11) - guest (Linux >= 2.6.24) - guest_nice (Linux >= 3.2.0) When *percpu* is True return a list of namedtuples for each CPU. First element of the list refers to first CPU, second element to second CPU and so on. The order of the list is consistent across calls. N)rzr\Z per_cpu_timesrrlrlrpr\qsrcCs0t|ƒ}tr,|t|ddƒ8}|t|ddƒ8}|S)zWGiven a cpu_time() ntuple calculates the total CPU time (including idle time). ZguestrZ guest_nice)ÚsumrrÐ)ÚtimesZtotrlrlrpÚ _cpu_tot_timeœs  r~cCs&t|ƒ}||j8}|t|ddƒ8}|S)zlGiven a cpu_time() ntuple calculates the busy CPU time. We do so by subtracting all idle CPU times. Ziowaitr)r~ÚidlerÐ)r}ÚbusyrlrlrpÚ_cpu_busy_time¯s rcCs\|j|jkst||fƒ‚g}tjjD],}t||ƒt||ƒ}td|ƒ}| |¡q$tj|ŽS)Nr)r%r<rzÚ scputimesrÐÚmaxrÛ)Út1Út2Z field_deltasÚfieldÚ field_deltarlrlrpÚ_cpu_times_deltas¿s   rˆc Csôt ¡j}|dk o|dk}|dk r:|dkr:d|}t|ƒ‚dd„}|s„|r\tƒ}t |¡nt |¡pjtƒ}tƒt|<||t|ƒSg}|r¢tdd}t |¡nt  |¡p´tdd}tddt |<t |t |ƒD]\}} |  ||| ƒ¡qÒ|SdS) a¡Return a float representing the current system-wide CPU utilization as a percentage. When *interval* is > 0.0 compares system CPU times elapsed before and after the interval (blocking). When *interval* is 0.0 or None compares system CPU times elapsed since last call or module import, returning immediately (non blocking). That means the first time this is called it will return a meaningless 0.0 value which you should ignore. In this case is recommended for accuracy that this function be called with at least 0.1 seconds between calls. When *percpu* is True returns a list of floats representing the utilization as a percentage for each CPU. First element of the list refers to first CPU, second element to second CPU and so on. The order of the list is consistent across calls. Examples: >>> # blocking, system-wide >>> psutil.cpu_percent(interval=1) 2.0 >>> >>> # blocking, per-cpu >>> psutil.cpu_percent(interval=1, percpu=True) [2.0, 1.0] >>> >>> # non-blocking (percentage since last call) >>> psutil.cpu_percent(interval=None) 2.9 >>> NrrrcSsPt||ƒ}t|ƒ}t|ƒ}z||d}Wntk r@YdSXt|dƒSdS)Nrrr)rˆr~rrr)r„r…Ú times_deltaÚ all_deltaZ busy_deltaZ busy_percrlrlrpÚ calculateýs zcpu_percent..calculateTr) r›Úcurrent_threadÚidentr‘r\rrÚ_last_cpu_timesÚgetÚ_last_per_cpu_timesÚziprÛ© rrÚtidr r‹r‹r„r|Ztot1r…rlrlrpr]Ôs,#      c Csôt ¡j}|dk o|dk}|dk r:|dkr:d|}t|ƒ‚dd„}|s„|r\tƒ}t |¡nt |¡pjtƒ}tƒt|<||t|ƒSg}|r¢tdd}t |¡nt  |¡p´tdd}tddt |<t |t |ƒD]\}} |  ||| ƒ¡qÒ|SdS) a·Same as cpu_percent() but provides utilization percentages for each specific CPU time as is returned by cpu_times(). For instance, on Linux we'll get: >>> cpu_times_percent() cpupercent(user=4.8, nice=0.0, system=4.8, idle=90.5, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0) >>> *interval* and *percpu* arguments have the same meaning as in cpu_percent(). NrrrcSsdg}t||ƒ}t|ƒ}dtd|ƒ}|D]0}||}t|dƒ}ttd|ƒdƒ}| |¡q(tj|ŽS)NgY@rr)rˆr~rƒrryrÛrzr‚)r„r…r5r‰rŠÚscaler‡Z field_percrlrlrpr‹9s   z$cpu_times_percent..calculateTr) r›rŒrr‘r\rrÚ_last_cpu_times_2rÚ_last_per_cpu_times_2r‘rÛr’rlrlrpr^&s,     cCst ¡S)zReturn CPU statistics.)rzr`rlrlrlrpr`asÚcpu_freqc Csºt ¡}|r|Stt|ƒƒ}|dkr(dS|dkr8|dSd\}}}d}|D]6}||j7}trl|jdkrld}qJ||j7}||j7}qJ||}|r˜d} } n||} ||} t  || | ¡SdS)a:Return CPU frequency as a namedtuple including current, min and max frequency expressed in Mhz. If *percpu* is True and the system supports per-cpu frequency retrieval (Linux only) a list of frequencies is returned for each CPU. If not a list with one element is returned. rNr)rrrFT) rzr—r(rÍÚcurrentrryrƒrZscpufreq) rr|rZcurrsZminsZmaxsZset_noneÚcpur˜Zmin_Zmax_rlrlrpr—hs.      Ú getloadavgcCst ¡}|ja|S)a€Return statistics about system memory usage as a namedtuple including the following fields, expressed in bytes: - total: total physical memory available. - available: the memory that can be given instantly to processes without the system going into swap. This is calculated by summing different memory values depending on the platform and it is supposed to be used to monitor actual memory usage in a cross platform fashion. - percent: the percentage usage calculated as (total - available) / total * 100 - used: memory used, calculated differently depending on the platform and designed for informational purposes only: macOS: active + wired BSD: active + wired + cached Linux: total - free - free: memory not being used at all (zeroed) that is readily available; note that this doesn't reflect the actual memory available (use 'available' instead) Platform-specific fields: - active (UNIX): memory currently in use or very recently used, and so it is in RAM. - inactive (UNIX): memory that is marked as not used. - buffers (BSD, Linux): cache for things like file system metadata. - cached (BSD, macOS): cache for various things. - wired (macOS, BSD): memory that is marked to always stay in RAM. It is never moved to disk. - shared (BSD): memory that may be simultaneously accessed by multiple processes. The sum of 'used' and 'available' does not necessarily equal total. On Windows 'available' and 'free' are the same. )rzrZr'r&rgrlrlrprZ£s5cCst ¡S)aåReturn system swap memory statistics as a namedtuple including the following fields: - total: total swap memory in bytes - used: used swap memory in bytes - free: free swap memory in bytes - percent: the percentage usage - sin: no. of bytes the system has swapped in from disk (cumulative) - sout: no. of bytes the system has swapped out from disk (cumulative) 'sin' and 'sout' on Windows are meaningless and always set to 0. )rzr[rlrlrlrpr[Þs cCs t |¡S)z£Return disk usage statistics about the given *path* as a namedtuple including total, used and free space expressed in bytes plus the percentage usage. )rzrg)rârlrlrprgóscCs t |¡S)a3Return mounted partitions as a list of (device, mountpoint, fstype, opts) namedtuple. 'opts' field is a raw string separated by commas indicating mount options which may vary depending on the platform. If *all* parameter is False return physical devices only and ignore all others. )rzrf)Úallrlrlrprfûs cCsŽtrt|dni}tjf|Ž}|s.|r*iSdS|r3sz#disk_io_counters..) rrnrzreÚ _wrap_numbersrÐrržr¶r‘Úvalues)rœÚnowraprWÚrawdictr2ZdiskÚfieldsrlrlrpres    rzClears nowrap argument cachecCsnt ¡}|s|riSdS|r&t|dƒ}|rN| ¡D]\}}tj|Ž||<q2|Stjdd„t| ¡ŽDƒŽSdS)acReturn network I/O statistics as a namedtuple including the following fields: - bytes_sent: number of bytes sent - bytes_recv: number of bytes received - packets_sent: number of packets sent - packets_recv: number of packets received - errin: total number of errors while receiving - errout: total number of errors while sending - dropin: total number of incoming packets which were dropped - dropout: total number of outgoing packets which were dropped (always 0 on macOS and BSD) If *pernic* is True return the same information for every network interface installed on the system as a dictionary with network interface names as the keys and the namedtuple described above as the values. If *nowrap* is True it detects and adjust the numbers which overflow and wrap (restart from 0) and add "old value" to "new value" so that the returned numbers will always be increasing or remain the same, but never decrease. "net_io_counters.cache_clear()" can be used to invalidate the cache. Núpsutil.net_io_counterscSsg|] }t|ƒ‘qSrlrŸrvrlrlrprqesz#net_io_counters..)rzrar¡r¶rZsnetior‘r¢)Zpernicr£r¤Znicr¥rlrlrpraAs  r¦r7cCs t |¡S)a˜Return system-wide socket connections as a list of (fd, family, type, laddr, raddr, status, pid) namedtuples. In case of limited privileges 'fd' and 'pid' may be set to -1 and None respectively. The *kind* parameter filters for connections that fit the following criteria: +------------+----------------------------------------------------+ | Kind Value | Connections using | +------------+----------------------------------------------------+ | inet | IPv4 and IPv6 | | inet4 | IPv4 | | inet6 | IPv6 | | tcp | TCP | | tcp4 | TCP over IPv4 | | tcp6 | TCP over IPv6 | | udp | UDP | | udp4 | UDP over IPv4 | | udp6 | UDP over IPv6 | | unix | UNIX socket (both UDP and TCP protocols) | | all | the sum of all the possible families and protocols | +------------+----------------------------------------------------+ On macOS this function requires root privileges. )rzrbr:rlrlrprbnsc Csôt}|rddl}t ¡}|jdd„dt t¡}|D]´\}}}}}} |rœz| |¡}WnBt k ršt r||dkr|tj }nt tdƒr–|tj kr–tj }YnX|tj krÎt r®dnd } | | ¡d krÎ|d | 7}q²|| t ||||| ¡¡q6t|ƒS) a*Return the addresses associated to each NIC (network interface card) installed on the system as a dictionary whose keys are the NIC names and value is a list of namedtuples for each address assigned to the NIC. Each namedtuple includes 5 fields: - family: can be either socket.AF_INET, socket.AF_INET6 or psutil.AF_LINK, which refers to a MAC address. - address: is the primary address and it is always set. - netmask: and 'broadcast' and 'ptp' may be None. - ptp: stands for "point to point" and references the destination address on a point to point interface (typically a VPN). - broadcast: and *ptp* are mutually exclusive. Note: you can have more than one address of the same family associated with each interface. rNcSs|dS)Nrrl)rwrlrlrpr.¡r/znet_if_addrs..)ÚkeyéÿÿÿÿrSú:ú-éz%s00)rŽÚsocketrzrcÚsortr¯r rÈÚ AddressFamilyr‘r,rSrÃrÚcountrÛrZsnicaddrrn) Z has_enumsr¬Zrawlistr|r§ÚfamÚaddrÚmaskÚ broadcastZptpÚ separatorrlrlrprc‹s0  ÿþ   cCst ¡S)aReturn information about each NIC (network interface card) installed on the system as a dictionary whose keys are the NIC names and value is a namedtuple with the following fields: - isup: whether the interface is up (bool) - duplex: can be either NIC_DUPLEX_FULL, NIC_DUPLEX_HALF or NIC_DUPLEX_UNKNOWN - speed: the NIC speed expressed in mega bits (MB); if it can't be determined (e.g. 'localhost') it will be set to 0. - mtu: the maximum transmission unit expressed in bytes. )rzrdrlrlrlrprd½s Úsensors_temperaturesc sœ‡fdd„}t t¡}t ¡}| ¡D]l\}}|r&| d¡\}}}} ||ƒ}||ƒ}|| ƒ} |rj| sj|} n | rv|sv| }|| t  |||| ¡¡q.q&t |ƒS)a<Return hardware temperatures. Each entry is a namedtuple representing a certain hardware sensor (it may be a CPU, an hard disk or something else, depending on the OS and its configuration). All temperatures are expressed in celsius unless *fahrenheit* is set to True. cs(|dk r$ˆr t|ƒdddS|SdS)Né r«é )r()Ún©Ú fahrenheitrlrpÚconvertÝsz%sensors_temperatures..convertr) r¯r rÈrzrµr¶r rÛrZshwtemprn) rºr»r|r¤r§r¢Úlabelr˜ÚhighÚcriticalrlr¹rprµÔs"  ÿÚ sensors_fanscCst ¡S)z¢Return fans speed. Each entry is a namedtuple representing a certain hardware sensor. All speed are expressed in RPM (rounds per minute). )rzr¿rlrlrlrpr¿üsÚsensors_batterycCst ¡S)ažReturn battery information. If no battery is installed returns None. - percent: battery power left as a percentage. - secsleft: a rough approximation of how many seconds are left before the battery runs out of power. May be POWER_TIME_UNLIMITED or POWER_TIME_UNLIMITED. - power_plugged: True if the AC power cable is connected. )rzrÀrlrlrlrprÀ s cCst ¡S)zAReturn the system boot time expressed in seconds since the epoch.)rzrirlrlrlrpri scCst ¡S)a„Return users currently connected on the system as a list of namedtuples including the following fields. - user: the name of the user - terminal: the tty or pseudo-tty associated with the user, if any. - host: the host name associated with the entry, if any. - started: the creation time as a floating point number expressed in seconds since the epoch. )rzrhrlrlrlrprh$ s cCst ¡S)zjReturn a generator yielding a WindowsService instance for all Windows services installed. )rzÚwin_service_iterrlrlrlrprÁ8 srÁcCs t |¡S)zjGet a Windows service by *name*. Raise NoSuchProcess if no service with such name exists. )rzÚwin_service_get)r§rlrlrprÂ> srÂcCs(ddl}t|ƒ|j_tj t|ƒ¡dS)zZEnable or disable PSUTIL_DEBUG option, which prints debugging messages to stderr. rN)Zpsutil._commonÚboolrZ PSUTIL_DEBUGrzr’Ú set_debug)röZpsutilrlrlrpÚ _set_debugH s rÅc CsXddlm}ddlm}tj ¡}d}ddddd d d d d dg }t|dƒt|ddD]ú}|j d rœtj  |j d ¡}| ¡|kr|  d¡}q |  d¡}nd}|j d rÈt   dt   t|j d ƒ¡¡}nd}|j dpØd}|strz| ¡d}Wntk r YnX|r2tr2d|kr2| d¡d}|dd…}|j d dk r^||j d jƒnd} |j d dk r‚||j d jƒnd} |j ddk r¦t|j ddƒnd} |j d rÄt|j d ƒnd} |j dræd |j d¡} n |j d} |j d r|j d dd…nd}||dd…|j d| | | | |||| f }t|d|ƒd…ƒqVdS)Nr)Ú bytes2human)Úget_terminal_sizez)%-10s %5s %5s %7s %7s %5s %6s %6s %6s %sr}r)r§rár\r¤rÄr¨r÷rô) ÚUSERZPIDz%MEMZVSZZRSSZNICEZSTATUSÚSTARTZTIMEZCMDLINE)rÓz%H:%Mz%b%drtz%M:%Srú\r¶ú r«é )rrÆÚ_compatrÇr€ÚdateÚtodayÚprintrXr·rr‚rÚ localtimer|rrÅr.r,ÚsplitÚvmsr$rrmrµ)rÆrÇZ today_dayZtemplrÒÚprÙZcputimerrÓr$Zmempr÷rár¨ÚlinerlrlrpÚtestR s€    ÿ      ÿ   ÿý ÿý ÿý  " ö rÖr,Ú__main__)NN)NN)T)F)NF)NF)F)F)FT)FT)r7)F)¼rMÚ __future__rr¯rPr€Ú functoolsrŒrArSÚsysr›rrírîrtrrrrrr r r r r rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r¡rÍr5rŽr6r7r8rsr9Z PROCFS_PATHr:rzr;r<r=r>r?Z_psutil_windowsr@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrÑÚplatformÚ__all__ÚextendZ__extra__all__rÃrTrkÚglobalsZ_globalsr•rXräÚisupperrÐrÛrSÚ __author__rRrÉrÒrQrr&rØr`r¢rmÚreplacer’rxr‹rµróruryr~r…rÊrÇrUrWrVrkrÞrXÚ cache_clearrYr_r\rŒrrŽÚ Exceptionrr~rrˆr]rlr•r–r^r`r—ršrZr[rgrfreÚpartialrarbrcrdrµr¿rÀrirhrÁrÂrÅrÖrorwr´rlrlrlrpÚsf                                                                            Ô1   ÿ þ  ýÿ   "ÿ W 6  b   ÿ  N ;  (   ; /ÿ 'ÿ 2  "       J