B Œ=Ý_ÝRãG@sþdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z y ddl Z Wnek r„dZ YnXddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#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"lm0Z0dd#lm1Z1dd$lm2Z2dd%lm3Z3dd&lm4Z4dd'lm5Z5dd(lm6Z6dd)lm7Z7dd*lm8Z8dd+lm9Z9dd,lm:Z:dd-lm;Z;dd.lmZ>dd1lm?Z?dd2lm@Z@dd3lmAZAdd4lmBZBdd5lmCZCdd6lmDZDdd7lmEZEdd8lmFZFe?r@d9ZGdd:lmHZIdd;lHmJZJddlHmMZMneFrØdd?lmNZIdd@lOmPZPddAlOmQZQddBlOmRZRddClOmSZSddDlOmTZTddElOmUZUddFlNmVZVddGlNmWZWddHlNmXZXddIlNmYZYddJlNmZZZn~e@rìddKlm[ZInje=rddLlm\ZInVeEr0ddMlm]ZIddNl]m^Z^ddOl]m_Z_d9ZGn&e<rHddPlm`ZId9ZGneadQe jbƒ‚dRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdbdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dd€dd‚dƒd„d…d†d‡dˆd‰dŠd‹dŒddŽddd‘d’d“d”d•d–d—gGZcec deIje¡efeIjgd˜ƒr^dd™lmhZheiƒZjdZkx@elehƒD]4Zkek mdš¡r"ek n¡r"eoehekƒejek<ec pek¡q"W[j[keIjqZqd›ZrdœZsetddž„es udŸ¡DƒƒZveoe d e j ƒZwdaxdayezƒZ{e|es }dŸd¡¡ƒeoeIj~d¢dƒkr:d£eoeIj~d¤ƒZefeIj~d¢ƒred¥dŸ €d¦dž„eeIj~j‚ƒDƒ¡esf7Zn ed§es7Zed¨eoeIj~d¤d©ƒ7Zedª7Zeeƒ‚efeId«ƒrNeIjƒZ„nd¬d­„Z„d®d¯„Z…d°d±„Z†Gd²d‚„d‚ezƒZge‡d³dž„elegƒDƒƒZˆGd´dƒ„dƒegƒZ‰dµd…„ZŠd¶d„„Z‹iZŒe  ¡ZŽdçd·d†„Zdèd¸d‡„Zdédºd„Z‘dêd¼dŠ„Z’y e’ƒa“Wne”k rda“YnXye’d¹d½a•Wne”k r.da•YnXd¾d¿„Z–dÀdÁ„Z—dÂdÄZ˜dëdÄd‹„Z™t“ašt•a›dìdÅdŒ„ZœdÆdŽ„ZefeIdǃrŒdídÈdÇ„Zžec pdÇ¡efedɃs¤efeIdɃrÈefedɃr¸ejŸZŸneIjŸZŸec pdÉ¡dÊdˆ„Z dËd‰„Z¡dÌd•„Z¢dîdÍd”„Z£dïdÎd“„Z¤e ¥ej¦dÏ¡e¤_¦dÐe¤j¦_dðdÑd„Z§e ¥ej¦dÒ¡e§_¦dÐe§j¦_dñdÔd„Z¨dÕd‘„Z©dÖd’„ZªefeId׃rhdòdØdׄZ«ec pdסefeIdÙƒr†dÚdÙ„Z¬ec pdÙ¡efeIdÛƒr¤dÜdÛ„Z­ec pdÛ¡dÝd—„Z®dÞd–„Z¯eFrÊdßdà„Z°dádâ„Z±dãdä„Z²[[e jvddåkrê[³[´eµdækrúe²ƒdS)óa3psutil 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 from 2.6 to 3.4+. é)ÚdivisionNé)Ú_common)Ú AccessDenied)ÚError)Úmemoize_when_activated)Ú NoSuchProcess)ÚTimeoutExpired)Ú wrap_numbers)Ú ZombieProcess)Úlong)ÚPermissionError)ÚProcessLookupError)ÚPY3)Ú 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)ÚNIC_DUPLEX_FULL)ÚNIC_DUPLEX_HALF)ÚNIC_DUPLEX_UNKNOWN)Ú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)ÚAIX)ÚBSD)ÚFREEBSD)ÚLINUX)ÚMACOS)ÚNETBSD)ÚOPENBSD)ÚOSX)ÚPOSIX)ÚSUNOS)ÚWINDOWSz/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_VERYLOW)Ú IOPRIO_LOW)Ú IOPRIO_NORMAL)Ú IOPRIO_HIGH)Ú_psosx)Ú_psbsd)Ú_pssunos)Ú CONN_BOUND)Ú CONN_IDLE)Ú_psaixzplatform %s is not supportedrrr rr Ú version_infoÚ __version__r&r#r'r"r(r)r,r!r+r$r*r%rrrrrrrrrrrrÚAF_LINKrrrrr r.r/r0r2r3r1r4r5r6r7r-Ú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'z5.8.0cCsg|] }t|ƒ‘qS©)Úint)Ú.0ÚnumrjrjúB/opt/alt/python37/lib64/python3.7/site-packages/psutil/__init__.pyú ÕsroÚ.Z monotonicÚÚversionzOversion conflict: %r C extension module was built for another version of psutilÚ__file__z (%s instead of %s)cCsg|]}|‘qSrjrj)rlÚxrjrjrnroèsz (different than %s)z;; you may try to 'pip uninstall psutil', manually remove %sz%the existing psutil install directoryz1 or clean the virtual env somehow, then reinstallÚppid_mapc CsHi}x>tƒD]4}yt |¡ ¡||<Wq ttfk r>Yq Xq W|S)z{Return a {pid: ppid, ...} dict for all running processes in one shot. Used to speed up Process.children(). )rUÚ _psplatformrRÚppidrr )ÚretÚpidrjrjrnÚ _ppid_mapûs  rzcst ˆ¡‡fdd„ƒ}|S)zpDecorator which raises NoSuchProcess in case a process is no longer running or its PID has been reused. cs&| ¡st|j|jƒ‚ˆ|f|ž|ŽS)N)Ú is_runningrryÚ_name)ÚselfÚargsÚkwargs)ÚfunrjrnÚwrapper sz'_assert_pid_not_reused..wrapper)Ú functoolsÚwraps)r€rrj)r€rnÚ_assert_pid_not_reusedsr„cCs8t ¡}t||ƒ}|dkr"d}nd}tj |¡ |¡S)z(Format seconds in a human readable form.i€Qz%H:%M:%Sz%Y-%m-%d %H:%M:%S)ÚtimerkÚdatetimeÚ fromtimestampÚstrftime)ZsecsZnowZsecs_agoZfmtrjrjrnÚ _pprint_secss  r‰c@sŽeZdZdZdydd„Zdzdd„Zdd „ZeZd d „Zd d „Z dd„Z e dd„ƒZ e jdd„ƒZd{dd„Zdd„Zdd„Zdd„Zedd„ƒZdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd|d,d-„Zerøed.d/„ƒZd0d1„Z d2d3„Z!d4d5„Z"e#e$j%d6ƒrd7d8„Z&e#e$j%d9ƒr&d}d:d;„Z'e#e$j%d<ƒr>d~d=d>„Z(e#e$j%d?ƒrVdd@dA„Z)e#e$j%dBƒrldCdD„Z*e#e$j%dEƒr‚dFdG„Z+e,rdHdI„Z-dJdK„Z.dLdM„Z/e#e$j%dNƒr¶dOdP„Z0e1d€dQdR„ƒZ2ddSdT„Z3edUdV„ƒZ4edWdX„ƒZ5e6j7dYdZd[d\„ƒZ8d]d^„Z9d‚d`da„Z:e#e$j%dbƒr$dƒddde„Z;dfdg„Ze1dmdn„ƒZ?e1dodp„ƒZ@e1dqdr„ƒZAe1dsdt„ƒZBe1dudv„ƒZCd…dwdx„ZDdS)†rRa'Represents 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 the PID of the process being queried has been reused over time. That means you might end up retrieving an information referring to another process in case the original one this instance refers to is gone in the meantime. 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 - if you're continuously iterating over a set of Process instances use process_iter() which pre-emptively checks process identity for every yielded instance NcCs| |¡dS)N)Ú_init)r}ryrjrjrnÚ__init__EszProcess.__init__FcCs|dkrt ¡}n2ts0t|ttfƒs0td|ƒ‚|dkrDtd|ƒ‚||_d|_ d|_ d|_ d|_ d|_ t ¡|_d|_t |¡|_d|_d|_t|_y | ¡WnXtk r¶YnFtk rÈYn4tk rú|sðd|}t|d|ƒ‚nd|_ YnX|j|j f|_dS)Nzpid must be an integer (got %r)rz'pid must be a positive integer (got %s)Fzno process found with pid %sT)ÚosÚgetpidÚ_PY3Ú isinstancerkr Ú TypeErrorÚ ValueErrorÚ_pidr|Ú_exeÚ _create_timeÚ_goneÚ_hashÚ threadingÚRLockÚ_lockÚ_ppidrvrRÚ_procÚ_last_sys_cpu_timesÚ_last_proc_cpu_timesÚ _SENTINELÚ _exitcodeÚ create_timerr rryÚ_ident)r}ryÚ _ignore_nspÚmsgrjrjrnrŠHs>      z Process._initc Csy t ¡}Wntk r$i}YnX|j|d<|jr@|j|d<| ¡¾y| ¡|d<| ¡|d<WnHtk r‚d|d<Yn.t k rœd|d<Ynt k r®YnX|j t dfkrÈ|j |d<|j rÜt|j ƒ|d<d|jj|jjd  d d „| ¡Dƒ¡fSQRXdS) NryÚnameÚstatusZzombieZ terminatedZexitcodeZstartedz %s.%s(%s)z, cSsg|]\}}d||f‘qS)z%s=%rrj)rlÚkÚvrjrjrnro‘sz#Process.__str__..)Ú collectionsÚ OrderedDictÚAttributeErrorryr|Úoneshotr¤r¥r rrrŸržr”r‰Ú __class__Ú __module__Ú__name__ÚjoinÚitems)r}ÚinforjrjrnÚ__str__xs2         zProcess.__str__cCst|tƒstS|j|jkS)N)rrRÚNotImplementedr¡)r}ÚotherrjrjrnÚ__eq__•s zProcess.__eq__cCs ||k S)Nrj)r}r´rjrjrnÚ__ne__œszProcess.__ne__cCs|jdkrt|jƒ|_|jS)N)r–Úhashr¡)r}rjrjrnÚ__hash__Ÿs  zProcess.__hash__cCs|jS)zThe process PID.)r’)r}rjrjrnry¤sz Process.pidc cs²|j¢t|dƒrdVnŠzH|j |¡|j |¡|j |¡trP|j |¡|j  ¡dVWd|j  |¡|j  |¡|j  |¡tr˜|j  |¡|j  ¡XWdQRXdS)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™ÚhasattrrZZcache_activateÚ memory_inforwr5Úuidsr›Z oneshot_enterZcache_deactivateZ oneshot_exit)r}rjrjrnr««s"           zProcess.oneshotc Cst}|dk rnt|ttttfƒs.tdt|ƒƒ‚t|ƒ}||}|rntdt |ƒdkrVdndd  t t |ƒ¡fƒ‚t ƒ}|pz|}| ¡xxp|D]h}y$|dkr¢|j}nt||ƒ} | ƒ}Wn6ttfk rÐ|}Yntk rê|rä‚wŒYnX|||<qŒWWdQRX|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Úsrqz, ry)Ú_as_dict_attrnamesrÚlistÚtupleÚsetÚ frozensetrÚtyper‘Úlenr¯ÚmapÚreprÚdictr«ryÚgetattrrr ÚNotImplementedError) r}ÚattrsÚad_valueZ valid_namesÚ invalid_namesZretdictÚlsr¤rxZmethrjrjrnÚas_dictîs6     zProcess.as_dictcCsrtdk r tntƒd}|j|kr$dS| ¡}|dk rn| ¡}yt|ƒ}| ¡|krV|SWntk rlYnXdS)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_PIDrUryrwr rRr)r}Z lowest_pidrwÚctimeÚparentrjrjrnrÑs  zProcess.parentcCs0g}| ¡}x|dk r*| |¡| ¡}qW|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ÚprocrjrjrnrÓ-s    zProcess.parentscCsJ|jr dSy|t|jƒkStk r,dStk rDd|_dSXdS)z•Return whether this process is running. It also checks if PID has been reused by another process in which case return False. FTN)r•rRryr r)r}rjrjrnr{8szProcess.is_runningcCs*tr|j ¡S|jp|j ¡|_|jSdS)z`The process parent PID. On Windows the return value is cached after first call. N)r5r›rwrš)r}rjrjrnrwPs  z Process.ppidcCs„tr|jdk r|jS|j ¡}trrt|ƒdkrry | ¡}Wntk rNYn$X|rrtj   |d¡}|  |¡rr|}||_||j_|S)z>The process name. The return value is cached after first call.Nér) r7r|r›r¤r5rÄÚcmdlinerrŒÚpathÚbasenameÚ startswith)r}r¤rÖZ extended_namerjrjrnr¤bs   z Process.namec s‚‡fdd„}ˆjdkr|yˆj ¡}Wn(tk rL}z ||dSd}~XYn0X|svy||d}Wntk rtYnX|ˆ_ˆ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ÖÚexe)r}rjrnÚguess_its   zProcess.exe..guess_itN)rÞ)r“r›rßr)r}ràrßÚerrrj)r}rnrß|s  z Process.execCs |j ¡S)z3The command line this process has been called with.)r›rÖ)r}rjrjrnrÖ£szProcess.cmdlinecCs$y |j ¡Stk rtSXdS)z2The process current status as a STATUS_* constant.N)r›r¥r r,)r}rjrjrnr¥§s zProcess.statuscCsTtrFtdkrtdƒ‚| ¡j}y t |¡jStk rBt|ƒSXn |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) r5ÚpwdÚ ImportErrorr¼ÚrealÚgetpwuidZpw_nameÚKeyErrorÚstrr›Úusername)r}Zreal_uidrjrjrnrè®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}rjrjrnr Às  zProcess.create_timecCs |j ¡S)z6Process current working directory as an absolute path.)r›Úcwd)r}rjrjrnréÉsz Process.cwdcCs8|dkr|j ¡S| ¡s(t|j|jƒ‚|j |¡dS)z'Get or set process niceness (priority).N)r›Znice_getr{rryr|Znice_set)r}ÚvaluerjrjrnÚniceÍs  z Process.nicecCs |j ¡S)zVReturn process UIDs as a (real, effective, saved) namedtuple. )r›r¼)r}rjrjrnr¼Øsz Process.uidscCs |j ¡S)zVReturn process GIDs as a (real, effective, saved) namedtuple. )r›Úgids)r}rjrjrnrìßsz Process.gidscCs |j ¡S)zVThe terminal associated with this process, if any, else None. )r›Úterminal)r}rjrjrnríåszProcess.terminalcCs |j ¡S)zcReturn the number of file descriptors opened by this process (POSIX only). )r›Únum_fds)r}rjrjrnrîë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}rjrjrnrïôszProcess.io_countersÚ ionice_getcCs4|dkr"|dk rtdƒ‚|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ðZ ionice_set)r}ZioclassrêrjrjrnÚionices  zProcess.ionicerhcCs|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. )r›rh)r}ÚresourceZlimitsrjrjrnrhs zProcess.rlimitÚcpu_affinity_getcCsd|dkrtt|j ¡ƒƒS|sLt|jdƒr6|j ¡}ntttt 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ôrÀÚrangerÄrZZcpu_affinity_setr¿)r}ZcpusrjrjrnÚ cpu_affinity%s  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›rù)r}rjrjrnrù:szProcess.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›rú)r}rjrjrnrúGszProcess.environcCs |j ¡S)z\Return the number of handles opened by this process (Windows only). )r›Ú num_handles)r}rjrjrnrûNszProcess.num_handlescCs |j ¡S)zkReturn the number of voluntary and involuntary context switches performed by this process. )r›Únum_ctx_switches)r}rjrjrnrüTszProcess.num_ctx_switchescCs |j ¡S)z2Return the number of threads used by this process.)r›Ú num_threads)r}rjrjrnrýZszProcess.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}rjrjrnrþ`szProcess.threadsc Cs<tƒ}g}|spx^| ¡D]R\}}||jkry&t|ƒ}| ¡| ¡krN| |¡Wqttfk rhYqXqWnÈt  t ¡}x"| ¡D]\}}|| |¡q„Wt ƒ}|jg} xŠ| r6|   ¡}||krÆq®|  |¡xb||D]V} y6t| ƒ}| ¡| ¡k} | r| |¡|  | ¡WqÚttfk r.YqÚXqÚWq®W|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. )rzr°ryrRr rÒrr r¨Ú defaultdictr¿rÁÚpopÚadd) r}Ú recursiverurxryrwZchildZreverse_ppid_mapÚseenÚstackZ child_pidZintimerjrjrnÚchildrenhs>     zProcess.childrenc s|dk o|dk}|dk r,|dkr,td|ƒ‚tƒp4d‰‡fdd„}|rr|ƒ}|j ¡}t |¡|ƒ}|j ¡}n<|j}|j}|ƒ}|j ¡}|dksž|dkr®||_||_dS|j|j|j |j }||} ||_||_y|| d} Wnt k rdSX| ˆ} 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 >>> Ngrz!interval is not positive (got %r)rcs tƒˆS)N)Ú_timerrj)Únum_cpusrjrnÚtimerÖsz"Process.cpu_percent..timeréd) r‘r]r›rZr…ÚsleeprœrÚuserÚsystemÚZeroDivisionErrorÚround) r}ÚintervalÚblockingrZst1Zpt1Zst2Zpt2Z delta_procZ delta_timeZoverall_cpus_percentZsingle_cpu_percentrj)rrnr[®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›rZ)r}rjrjrnrZ 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 plaforms are `rss` and `vms`. All numbers are expressed in bytes. )r›r»)r}rjrjrnr»s zProcess.memory_infor»)Z replacementcCs| ¡S)N)r»)r}rjrjrnÚmemory_info_ex szProcess.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_info)r}rjrjrnr$szProcess.memory_full_infoÚrsscCs€ttjjƒ}||kr(td|t|ƒfƒ‚|tjjkr:|jn|j}|ƒ}t ||ƒ}t pZt ƒj }|dksptd|ƒ‚|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¿rvZpfullmemÚ_fieldsr‘rÀZpmemr»rrÈÚ _TOTAL_PHYMEMrXÚtotalÚfloat)r}ZmemtypeZ valid_typesr€ZmetricsrêZ total_phymemrjrjrnÚmemory_percent4s   zProcess.memory_percentÚ memory_mapsTc s¤|j ¡}|rˆi‰xZ|D]R}|d}|dd…}ytdd„ˆ||ƒˆ|<Wqtk rh|ˆ|<YqXqWtj‰‡‡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||S)Nrj)rtÚyrjrjrnÚdóz%Process.memory_maps..csg|]}ˆ|fˆ|žŽ‘qSrjrj)rlr×)ÚdÚntrjrnrohsz'Process.memory_maps..csg|] }ˆ|Ž‘qSrjrj)rlrt)r rjrnroks)r›rrÅrærvZ pmmap_groupedZ pmmap_ext)r}ZgroupedÚitZtuplr×Únumsrj)rr rnrRs   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_files)r}rjrjrnr#mszProcess.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›Ú connections)r}Úkindrjrjrnr%tszProcess.connectionscCs¨|jdkrt|jƒ‚|jdkr&tdƒ‚yt |j|¡Wnjtk r‚trjt|jƒrjt|j|j |j ƒ‚nd|_ t |j|j ƒ‚Yn"t k 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)ryÚAssertionErrorr‘rŒÚkillrr3rTr r|ršr•rr r)r}ÚsigrjrjrnÚ _send_signals zProcess._send_signalcCs tr| |¡n |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(). N)r5r*r›Ú send_signal)r}r)rjrjrnr+¤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 ot suspending all process threads. N)r5r*ÚsignalÚSIGSTOPr›Úsuspend)r}rjrjrnr.°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)r5r*r,ÚSIGCONTr›Úresume)r}rjrjrnr0»szProcess.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)r5r*r,ÚSIGTERMr›r()r}rjrjrnÚ terminateÆszProcess.terminatecCs tr| tj¡n |j ¡dS)zjKill the current process with SIGKILL pre-emptively checking whether PID has been reused. N)r5r*r,ÚSIGKILLr›r()r}rjrjrnr(Ñsz Process.killcCs<|dk r|dkstdƒ‚|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}Útimeoutrjrjrnr4Ûs  z Process.wait)N)F)NN)N)NN)N)N)F)N)r)T)r$)N)Er®r­Ú __qualname__Ú__doc__r‹rŠr²Ú__repr__rµr¶r¸ÚpropertyryÚ contextlibÚcontextmanagerr«rÎrÑrÓr{rrwr¤rßrÖr¥rèr rérër5r¼rìrírîrºrvrRrïrñrhrørùrúr7rûrürýrþr„rr[rZr»rZdeprecated_methodrrrrr#r%r*r+r.r0r2r(r4rjrjrjrnrR$s„  0 C ,  '         E \     cCs"g|]}| d¡s|dkr|‘qS)Ú_)r+r.r0r2r(r4r{rÎrÑrÓrrhrr«)rÙ)rlrtrjrjrnroóscsJeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd‡fd d„ Z ‡Z S)rSa Same 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¢)Ú subprocessrSÚ_Popen__subprocrŠry)r}r~rrjrjrnr‹szPopen.__init__cCsttttƒttjƒƒƒS)N)rörÁÚdirrSr=)r}rjrjrnÚ__dir__#sz Popen.__dir__cCst|jdƒr|j ¡|S)NÚ __enter__)rºr>rA)r}rjrjrnrA&s  zPopen.__enter__cOs^t|jdƒr|jj||ŽS|jr*|j ¡|jr:|j ¡z|jrL|j ¡Wd| ¡XdS)NÚ__exit__)rºr>rBÚstdoutÚcloseÚstderrÚstdinr4)r}r~rrjrjrnrB+s   zPopen.__exit__c Cs^y t ||¡Stk rXyt |j|¡Stk rRtd|jj|fƒ‚YnXYnXdS)Nz!%s instance has no attribute '%s')ÚobjectÚ__getattribute__rªr>r¬r®)r}r¤rjrjrnrH;s zPopen.__getattribute__Ncs0|jjdk r|jjStt|ƒ |¡}||j_|S)N)r>Ú returncodeÚsuperrSr4)r}r5rx)r¬rjrnr4Es  z Popen.wait)N) r®r­r6r7r‹r@rArBrHr4Ú __classcell__rjrj)r¬rnrSþs cCstt ¡ƒ}|da|S)z&Return a list of current running PIDs.r)rörvrUrÏ)rxrjrjrnrURs 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)r5rUrvrT)ryrjrjrnrTZs   c #sT‡‡fdd„}dd„}ttƒƒ}tt ¡ƒ}||}||}x|D] }||ƒqBWt(ttt ¡ƒtt  |¡ ¡ƒƒ} WdQRXxÊ| D]Â\}} yJ| dkr¨||ƒVn2|   ¡rЈdk rÈ| j ˆˆd| _ | Vn ||ƒVWqŠt k rø||ƒYqŠtk rJ| dkrD|tkrDyt|VWntk r@YnXn‚YqŠXqŠWdS)aReturn 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. Cached Process instances are checked for identity so that you're safe in case a PID has been reused by another process, in which case the cached instance is updated. 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). c s>t|ƒ}ˆdk r |jˆˆd|_t|t|j<WdQRX|S)N)rÊrË)rRrÎr±r™Ú_pmapry)ryrÔ)rËrÊrjrnr…s zprocess_iter..addc Ss tt |d¡WdQRXdS)N)r™rLr)ryrjrjrnÚremoveszprocess_iter..removeN)rÊrË)rÁrUrLÚkeysr™rör¿r°rÇÚfromkeysr{rÎr±rrræ) rÊrËrrMÚaÚbZnew_pidsZ gone_pidsryrÍrÔrj)rËrÊrnrVps<         c s‡‡fdd„}|dk r.|dks.d|}t|ƒ‚tƒ‰t|ƒ}ˆdk rXtˆƒsXtdtƒ‚|dk rjtƒ|}xt|rÞ|dk r‚|dkr‚PxP|D]H}dt|ƒ}|dk rÆt|tƒ|ƒ}|dkrºP|||ƒqˆ|||ƒqˆW|ˆ}qlW|rx|D]}||dƒqìW|ˆ}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() csZy|j|d}Wntk r$Yn2X|dk s6| ¡sV||_ˆ |¡ˆdk rVˆ|ƒdS)N)r5)r4r r{rIr)rÔr5rI)ÚcallbackÚgonerjrnÚ check_goneßs zwait_procs..check_goneNrz*timeout must be a positive integer, got %szcallback %r is not a callablegð?)r‘rÁÚcallablerrrÄÚminr¿) Zprocsr5rRrTr£ZaliveZdeadlinerÔZ max_timeoutrj)rRrSrnrW»s6$        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)rvZcpu_count_logicalZcpu_count_physical)Zlogicalrxrjrjrnr]s  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)rvrZZ per_cpu_times)rõrjrjrnrZ0s)rõcCs0t|ƒ}tr,|t|ddƒ8}|t|ddƒ8}|S)zWGiven a cpu_time() ntuple calculates the total CPU time (including idle time). ZguestrZ guest_nice)Úsumr0rÈ)ÚtimesZtotrjrjrnÚ _cpu_tot_timeYs  rYcCs&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)rYZidlerÈ)rXZbusyrjrjrnÚ_cpu_busy_timels rZcCs`|j|jkst||fƒ‚g}x8tjjD],}t||ƒt||ƒ}td|ƒ}| |¡q&Wtj|ŽS)Nr)rr'rvÚ scputimesrÈÚmaxrÒ)Út1Út2Z field_deltasZfieldÚ field_deltarjrjrnÚ_cpu_times_deltas|s r`cCsÞ|dk o|dk}|dk r,|dkr,td|ƒ‚dd„}|sp|rNtƒ}t |¡nt}|dkr`tƒ}tƒa||tƒSg}|rŽtdd}t |¡nt}|dkr¤tdd}tddax&t|tƒD]\}}| |||ƒ¡qºW|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 >>> Ngrz!interval is not positive (got %r)cSsNt||ƒ}t|ƒ}t|ƒ}y||d}Wntk r>dSXt|dƒSdS)Nr gr)r`rYrZr r)r]r^Ú times_deltaÚ all_deltaZ busy_deltaZ busy_percrjrjrnÚ calculateºs zcpu_percent..calculateT)rõ)r‘rZr…r Ú_last_cpu_timesÚ_last_per_cpu_timesÚziprÒ)rrõrrcr]rxÚtot1r^rjrjrnr[‘s0%       cCsÞ|dk o|dk}|dk r,|dkr,td|ƒ‚dd„}|sp|rNtƒ}t |¡nt}|dkr`tƒ}tƒa||tƒSg}|rŽtdd}t |¡nt}|dkr¤tdd}tddax&t|tƒD]\}}| |||ƒ¡qºW|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(). Ngrz!interval is not positive (got %r)cSshg}t||ƒ}t|ƒ}dtd|ƒ}x8|D]0}||}t|dƒ}ttd|ƒdƒ}| |¡q*Wtj|ŽS)NgY@rg)r`rYr\rrVrÒrvr[)r]r^r"rarbZscaler_Z field_percrjrjrnrcs   z$cpu_times_percent..calculateT)rõ)r‘rZr…r Ú_last_cpu_times_2Ú_last_per_cpu_times_2rfrÒ)rrõrrcr]rxrgr^rjrjrnr\ïs0       cCst ¡S)zReturn CPU statistics.)rvr^rjrjrjrnr^4sÚcpu_freqc Cs¾t ¡}|r|Stt|ƒƒ}|dkr(dS|dkr8|dSd\}}}d}x>|D]6}||j7}trn|jdkrnd}qL||j7}||j7}qLW||}|rœd} } n||} ||} t  || | ¡SdS)a9Return CPU frequency as a nameduple 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)gggFT) rvrjrrÄÚcurrentr0rVr\rZscpufreq) rõrxrZcurrsZminsZmaxsZset_noneZcpurkZmin_Zmax_rjrjrnrj;s.      Ú 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. )rvrXrr)rxrjrjrnrXvs5cCst ¡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. )rvrYrjrjrjrnrY±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. )rvre)r×rjrjrnreÆscCs\dd„}t |¡}trTg}x4|D],}|j||jdƒ||jdƒd}| |¡q W|S|SdS)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. c Ss*y t ||¡Sttfk r$YnXdS)N)rŒÚpathconfÚOSErrorrª)r×r¤rjrjrnrm×s z!disk_partitions..pathconfÚ PC_NAME_MAXÚ PC_PATH_MAX)ZmaxfileZmaxpathN)rvrdr5Ú_replaceZ mountpointrÒ)ÚallrmrxÚnewÚitemr rjrjrnrdÎs    cCs’trt|dni}tjf|Ž}|s.|r*iSdS|r.) r0rÇrvrcÚ _wrap_numbersrÈrrvr°rfÚvalues)ruÚnowraprÚrawdictr ZdiskÚfieldsrjrjrnrcês    zpsutil.disk_io_counterszClears nowrap argument cachecCsrt ¡}|s|riSdS|r&t|dƒ}|rRx"| ¡D]\}}tj|Ž||<q4W|Stjdd„t| ¡ŽDƒŽSdS)adReturn 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. "disk_io_counters.cache_clear()" can be used to invalidate the cache. Nzpsutil.net_io_counterscSsg|] }t|ƒ‘qSrj)rW)rlrtrjrjrnroGsz#net_io_counters..)rvr_rwr°rZsnetiorfrx)ZpernicryrzZnicr{rjrjrnr_#s  zpsutil.net_io_countersr$cCs 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. )rvr`)r&rjrjrnr`Osc Cstjdk}|rddl}t ¡}|jdd„dt t¡}xÀ|D]¸\}}}}}} |r¤y|  |¡}WnBt k r¢t r„|dkr„tj }nt tdƒržtj |kržtj }YnX|tj krÚtr¶d nd } x| | ¡d krØ|d | 7}q¼W|| t ||||| ¡¡q>Wt|ƒ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. )rérNcSs|dS)Nrrj)rtrjrjrnr‚rznet_if_addrs..)ÚkeyéÿÿÿÿrQú:ú-éz%s00)ÚsysrOÚsocketrvraÚsortr¨rÿr¿Z AddressFamilyr‘r7rQrºr5ÚcountrÒrZsnicaddrrÇ) Z has_enumsrƒZrawlistrxr¤ZfamZaddrÚmaskZ broadcastZptpZ separatorrjrjrnrals,         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. )rvrbrjrjrjrnrbœs Úsensors_temperaturesc s¤‡fdd„}t t¡}t ¡}x|| ¡D]p\}}xf|r–| d¡\}}}} ||ƒ}||ƒ}|| ƒ} |rn| sn|} n | rz|sz| }|| t  |||| ¡¡q2Wq(Wt |ƒ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)Ú fahrenheitrjrnÚconvert»sz%sensors_temperatures..convertr) r¨rÿr¿rvr‡r°rrÒrZshwtemprÇ) r‹rŒrxrzr¤rxZlabelrkZhighZcriticalrj)r‹rnr‡³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). )rvrrjrjrjrnrÙ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. )rvrŽrjrjrjrnrŽæs cCst ¡S)zAReturn the system boot time expressed in seconds since the epoch.)rvrgrjrjrjrnrgú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. )rvrfrjrjrjrnrf s cCst ¡S)zjReturn a generator yielding a WindowsService instance for all Windows services installed. )rvÚwin_service_iterrjrjrjrnr srcCs t |¡S)zjGet a Windows service by *name*. Raise NoSuchProcess if no service with such name exists. )rvÚwin_service_get)r¤rjrjrnr src Cs^ddlm}ddlm}tj ¡}d}ddddd d d d d dg }t|dƒx 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}|stry| ¡d}Wntk rYnX|r6tr6d|kr6| d¡d}|dd…}|j d dk rb||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…ƒqZWdS)Nr)Ú bytes2human)Úget_terminal_sizez)%-10s %5s %5s %7s %7s %5s %6s %6s %6s %sryrr¤rÖrZr r»r¥rërè) ZUSERZPIDz%MEMZVSZZRSSZNICEZSTATUSZSTARTZTIMEZCMDLINE)rËz%H:%Mz%b%drqz%M:%Srú\rˆú ré )rr‘Ú_compatr’r†ZdateZtodayÚprintrVr±r‡rˆr…Z localtimerWr5r¼rr7ÚsplitÚvmsrrrkr¯)r‘r’Z today_dayZtemplrÊÚprÐZcputimer r™rZmemprërÖr¥ÚlinerjrjrnÚtest% s^            $$$  " rœrÚ__main__)NN)NN)T)F)NF)NF)F)F)FT)FT)r$)F)¶r7Z __future__rr¨r:r†r‚rŒr,r=r‚r—r…rârãrqrrrrrr r rwr r–r r rrrŽrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7Z PROCFS_PATHr8rvr9r:r;r<r=Z_psutil_windowsr>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrÉÚplatformÚ__all__ÚextendZ__extra__all__rºrRriÚglobalsZ_globalsr|r?rÙÚisupperrÈrÒrQÚ __author__rPrÀr˜rOrrrÏrGržrkÚreplaceZcextr£r¯rçrrrurzr„r‰rÁr¾rSrUrTrLZLockr™rVrWr]rZrdÚ ExceptionrerYrZr`r[rhrir\r^rjrlrXrYrerdrcÚpartialÚ cache_clearr_r`rarbr‡rrŽrgrfrrrœrmrtr®rjrjrjrnÚsÜ                                                                            &     U T K ^      Z E  (   ;  /  '  0       =