\cG@ s dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z yddlZWnek reZnXddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlm 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-ddlm.Z.ddlm/Z/dd lm0Z0dd!lm1Z1dd"lm2Z2dd#lm3Z3dd$lm4Z4dd%lm5Z5dd&lm6Z6dd'lm7Z7dd(lm8Z8dd)lm9Z9dd*lm:Z:dd+lm;Z;dd,lm<Z<dd-lm=Z=dd.lm>Z>dd/lm?Z?dd0lm@Z@dd1lmAZAe:rtd2ZBdd3lmCZDdd4lCmEZEdd5lCmFZFdd6lCmGZGdd7lCmHZHeDjIrqdd8lJmKZKdd9lJmLZLdd:lJmMZMdd;lJmNZNdd<lJmOZOdd=lJmPZPdd>lJmQZQdd?lJmRZRdd@lJmSZSddAlJmTZTddBlJmUZUddClJmVZVddDlmJZJy eJjWZWWneXk rnXy eJjYZYWneXk r nXy eJjZZZWneXk r+nXy eJj[Z[WneXk rLnXy eJj\Z\WneXk rmnXnnleAr=ddElm]ZDddFl^m_Z_ddGl^m`Z`ddHl^maZaddIl^mbZbddJl^mcZcddKl^mdZdddLl]meZeddMl]mfZfddNl]mgZgddOl]mhZhddPl]miZine;rVddQlmjZDne8roddRlmkZDnqe@rddSlmlZDddTllmmZmddUllmnZnd2ZBn2e7rddVlmoZDd2ZBnepdWe jqdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidhdjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddddddddddddddddddddddddddddddgGZrerjseDjtdZudZvewgevjxdD]Zyezey^qZ{e|e de j Z}eDj~Z~ejZejZeaeaezevjdde|eDjdekr de|eDjdZeeDjdreddjgeeDjjD] Ze^qevf7Znedev7Zede|eDjdd7Zed7ZeendXefdYZdYefdYZdZefdYZd[efdYZd\efdYZeeD_eeD_eeD_eeD_e?r ddlmZee_neeDdr eDjZn dZdZdZdefdYZdefdYZegeeD]RZejd o eddddddddddddddgkr e^q? ZdZdZiZe jZeedZeedZedZedZy eaWnek r eanXyedeaWnek rG eanXdZdZdZeedZtataeedZdZeeDdr edZerjdneedp eeDdr eedr ejZn eDjZerjdndZdZdZedZeedZejejde_dej_eedZejejde_dej_ddZdZdZeeDdr edZerjdneeDdr dZerjdneeDdr9 dZerjdndZdZeArf dZdZndZ[[[[e j{ddkr [y[nedkr endS(s3psutil 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+. i(tdivisionNi(t_common(tdeprecated_method(tmemoize(tmemoize_when_activated(t wrap_numbers(tlong(tPY3(t STATUS_DEAD(tSTATUS_DISK_SLEEP(t STATUS_IDLE(t STATUS_LOCKED(t STATUS_PARKED(tSTATUS_RUNNING(tSTATUS_SLEEPING(tSTATUS_STOPPED(tSTATUS_TRACING_STOP(tSTATUS_WAITING(t STATUS_WAKING(t STATUS_ZOMBIE(t CONN_CLOSE(tCONN_CLOSE_WAIT(t CONN_CLOSING(tCONN_ESTABLISHED(tCONN_FIN_WAIT1(tCONN_FIN_WAIT2(t CONN_LAST_ACK(t CONN_LISTEN(t CONN_NONE(t CONN_SYN_RECV(t CONN_SYN_SENT(tCONN_TIME_WAIT(tNIC_DUPLEX_FULL(tNIC_DUPLEX_HALF(tNIC_DUPLEX_UNKNOWN(tAIX(tBSD(tFREEBSD(tLINUX(tMACOS(tNETBSD(tOPENBSD(tOSX(tPOSIX(tSUNOS(tWINDOWSs/proc(t_pslinux(tIOPRIO_CLASS_BE(tIOPRIO_CLASS_IDLE(tIOPRIO_CLASS_NONE(tIOPRIO_CLASS_RT(t RLIM_INFINITY(t RLIMIT_AS(t RLIMIT_CORE(t RLIMIT_CPU(t RLIMIT_DATA(t RLIMIT_FSIZE(t RLIMIT_LOCKS(tRLIMIT_MEMLOCK(t RLIMIT_NOFILE(t RLIMIT_NPROC(t RLIMIT_RSS(t RLIMIT_STACK(t _psutil_linux(t _pswindows(tABOVE_NORMAL_PRIORITY_CLASS(tBELOW_NORMAL_PRIORITY_CLASS(tHIGH_PRIORITY_CLASS(tIDLE_PRIORITY_CLASS(tNORMAL_PRIORITY_CLASS(tREALTIME_PRIORITY_CLASS(tCONN_DELETE_TCB(tIOPRIO_VERYLOW(t IOPRIO_LOW(t IOPRIO_NORMAL(t IOPRIO_HIGH(t_psosx(t_psbsd(t_pssunos(t CONN_BOUND(t CONN_IDLE(t_psaixsplatform %s is not supportedtErrort NoSuchProcesst ZombieProcesst AccessDeniedtTimeoutExpiredt version_infot __version__R R RR RRRRRR RR RRRRRRRRRRRRtAF_LINKR R!R"tPOWER_TIME_UNKNOWNtPOWER_TIME_UNLIMITEDR$R%R&R(R)R'R*R+R,R-R#tProcesstPopent pid_existstpidst process_itert wait_procstvirtual_memoryt swap_memoryt cpu_timest cpu_percenttcpu_times_percentt cpu_countt cpu_statstnet_io_counterstnet_connectionst net_if_addrst net_if_statstdisk_io_counterstdisk_partitionst disk_usagetuserst boot_timesGiampaolo Rodola's5.6.3t.t monotonicttversionsOversion conflict: %r C extension module was built for another version of psutilt__file__s (%s instead of %s)s (different than %s)s;; you may try to 'pip uninstall psutil', manually remove %ss%the existing psutil install directorys1 or clean the virtual env somehow, then reinstallcB s)eZdZddZdZeZRS(sQBase exception class. All other psutil exceptions inherit from this one. RtcC stj||||_dS(N(t Exceptiont__init__tmsg(tselfRy((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRx scC s#d|jj|jf}|jS(Ns psutil.%s %s(t __class__t__name__Rytstrip(Rztret((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt__repr__s(R|t __module__t__doc__RxRt__str__(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRRs  cB seZdZdddZRS(sXException raised when a process with a certain PID doesn't or no longer exists. cC s}tj||||_||_||_|dkry|r\d|jt|jf}n d|j}d||_ndS(Ns(pid=%s, name=%s)s(pid=%s)sprocess no longer exists (RRRxtpidtnameRytNonetrepr(RzRRRytdetails((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRxs     N(R|RRRRx(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRSscB s eZdZddddZRS(s1Exception raised when querying a zombie process. This is raised on macOS, BSD and Solaris only, and not always: depending on the query the OS may be able to succeed anyway. On Linux all zombie processes are querable (hence this is never raised). Windows doesn't have zombie processes. cC stj||||_||_||_||_|dkrd|g}|rp|jdt|jn|r|jd|jnddj |}d||_ndS(Nspid=%ssname=%ssppid=%ss(%s)s, s'process still exists but it's a zombie ( RSRxRtppidRRyRtappendRtjoin(RzRRRRytargsR((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRx/s      N(R|RRRRx(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRT'scB s eZdZddddZRS(s@Exception raised when permission to perform an action is denied.cC stj||||_||_||_|dkr|dk rk|dk rkd|t|f|_q|dk rd|j|_qd|_ndS(Ns(pid=%s, name=%s)s(pid=%s)Rt(RRRxRRRyRR(RzRRRy((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRxBs     N(R|RRRRx(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRU?scB seZdZdddZRS(sWRaised on Process.wait(timeout) if timeout expires and process is still alive. cC stj|d|||_||_||_|dk ri|dk ri|jd|t|f7_n%|dk r|jd|j7_ndS(Nstimeout after %s secondss (pid=%s, name=%s)s (pid=%s)(RRRxtsecondsRRRRyR(RzRRR((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRxUs   " N(R|RRRRx(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRVPs(t_psposixtppid_mapcC sUi}xHtD]=}ytj|j||erd:Z?ne2d;Z@e2d<ZAe2d=ZBe2d>ZCe2d?ZDdAd@ZERS(Bs'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 cC s|j|dS(N(t_init(RzR((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRxscC se|dkrtj}nOt rKt|ttf rKtd|n|dkrjtd|n||_ d|_ d|_ d|_ t |_d|_tj|_d|_tj||_d|_d|_y|jWn_tk rnOtk r n?tk rK|s?d|}t|d|qLt|_nX|j|j f|_dS(Nspid must be an integer (got %r)is'pid must be a positive integer (got %s)sno process found with pid %s( Rtostgetpidt_PY3t isinstanceRRt TypeErrort ValueErrort_pidRt_exet _create_timetFalset_gonet_hasht threadingtRLockt_lockt_ppidRR\t_proct_last_sys_cpu_timest_last_proc_cpu_timest create_timeRURTRStTrueRt_ident(RzRt _ignore_nspRy((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs<                 c C sytj}Wntk r)i}nX|j|d>> 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 ... >>> t_cacheN( RthasattrRdtcache_activatet memory_infoRR+tuidsRt oneshot_entertcache_deactivatet oneshot_exit(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pytoneshots"   c C sbt}|dk rt|ttttfsFtdt|nt|}||}|rt dt |dkrdnddj t t |fqnt}|p|}|jx|D]}y4|dkr|j}nt||} | }Wn<ttfk r*|}n tk rI|rqqnX|||The process name. The return value is cached after first call.iiN( R-RRRRR+RtcmdlineRURtpathtbasenamet startswith(RzRRt extended_name((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs   c sfd}jdkryjj}Wntk rP}|d|SX|sy|d|}Wqtk r}qXn|_njS(sThe process executable as an absolute path. May also be an empty string. The return value is cached after first call. c sj}|rzttdrzttdrz|d}tjj|rztjj|rztj|tjrz|Snt|t r|n|S(NtaccesstX_OKi( RRRRtisabstisfileRRRRU(tfallbackRtexe(Rz(s5/usr/lib64/python2.7/site-packages/psutil/__init__.pytguess_its $  RN(RRRRRU(RzRRterr((Rzs5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs  cC s |jjS(s3The command line this process has been called with.(RR(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRscC s*y|jjSWntk r%tSXdS(s2The process current status as a STATUS_* constant.N(RRRTR(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs cC sstrbtdkr!tdn|jj}ytj|jSWqotk r^t |SXn |j j SdS(stThe name of the user that owns the process. On UNIX this is calculated by using *real* process uid. s0requires pwd module shipped with standard pythonN( R+tpwdRt ImportErrorRtrealtgetpwuidtpw_nametKeyErrortstrRtusername(Rztreal_uid((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs   cC s+|jdkr$|jj|_n|jS(sThe process creation time as a floating point number expressed in seconds since the epoch, in UTC. The return value is cached after first call. N(RRRR(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR1scC s |jjS(s6Process current working directory as an absolute path.(Rtcwd(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR:scC sQ|dkr|jjS|js=t|j|jn|jj|dS(s'Get or set process niceness (priority).N(RRtnice_getRRSRRtnice_set(Rztvalue((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pytnice>s    cC s |jjS(sVReturn process UIDs as a (real, effective, saved) namedtuple. (RR(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRIscC s |jjS(sVReturn process GIDs as a (real, effective, saved) namedtuple. (Rtgids(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR PscC s |jjS(sVThe terminal associated with this process, if any, else None. (Rtterminal(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR VscC s |jjS(scReturn the number of file descriptors opened by this process (POSIX only). (Rtnum_fds(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR \st io_counterscC s |jjS(s 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. (RR (Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR est ionice_getcC sK|dkr4|dk r'tdn|jjS|jj||SdS(sGet 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. s$'ioclass' argument must be specifiedN(RRRRt ionice_set(RztioclassR((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pytioniceqs   trlimitcC s3|dkr|jj|S|jj||SdS(s"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 only. N(RRR(Rztresourcetlimits((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs tcpu_affinity_getcC s|dkr%tt|jjS|sst|jdrO|jj}qsttt t dt }n|jj tt|dS(s-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). t_get_eligible_cpustpercpuN( RRRRRRRRtrangeRRdRtcpu_affinity_set(Rztcpus((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt cpu_affinitys $tcpu_numcC s |jjS(sZReturn 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. (RR(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRstenvironcC s |jjS(sThe environment variables of the process as a dict. Note: this might not reflect changes made after the process started. (RR(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRscC s |jjS(s\Return the number of handles opened by this process (Windows only). (Rt num_handles(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRscC s |jjS(skReturn the number of voluntary and involuntary context switches performed by this process. (Rtnum_ctx_switches(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRscC s |jjS(s2Return the number of threads used by this process.(Rt num_threads(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR stthreadscC s |jjS(sReturn 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. (RR!(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR!sc C st}g}|sx|jD]p\}}||jkr"y8t|}|j|jkrt|j|nWqttfk rqXq"q"Wntj t }x+|jD]\}}||j|qWt }|jg} x| r| j }||krqn|j |xw||D]k} yKt| }|j|jk} | rz|j|| j| nWq*ttfk rq*Xq*WqW|S(s(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. (RRRR\RRRSRTRt defaultdictRRtpoptadd( Rzt recursiveRR~RRtchildtreverse_ppid_maptseentstackt child_pidtintime((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pytchildrens>           c  s{|dk o|dk}|dk rC|dkrCtd|ntpOdfd}|r|}|jj}tj||}|jj}nX|j}|j}|}|jj}|dks|dkr||_||_dS|j |j |j |j }||} ||_||_y|| d} Wnt k r_dSX| } t | dSdS(sReturn 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 >>> gis!interval is not positive (got %r)ic s tS(N(t_timer((tnum_cpus(s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyttimerJsidN( RRRgRRdRtsleepRRtusertsystemtZeroDivisionErrortround( RztintervaltblockingR/tst1tpt1tst2tpt2t delta_proct delta_timetoverall_cpus_percenttsingle_cpu_percent((R.s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRe"s:#             cC s |jjS(s%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. (RRd(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRd~s cC s |jjS(sReturn 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. (RR(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs t replacementRcC s |jS(N(R(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pytmemory_info_exscC s |jjS(s]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. (Rtmemory_full_info(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRAstrsscC sttjj}||kr=td|t|fn|tjjkrX|jn|j}|}t ||}t pt j }|dkstd|n|t |dS(sCompare 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') s&invalid memtype %r; valid types are %ris`can't calculate process memory percent because total physical system memory is not positive (%r)id(RRtpfullmemt_fieldsRRtpmemRRARt _TOTAL_PHYMEMRbttotaltfloat(Rztmemtypet valid_typesRtmetricsRt total_phymem((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pytmemory_percents      t memory_mapsc C s|jj}|ri}xa|D]Y}|d}|d}y!td|||||sN(RRNRRRt pmmap_groupedt pmmap_ext( RztgroupedtittdttuplRtnumstntRO((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRNs    !  $ cC s |jjS(sReturn files opened by process as a list of (path, fd) namedtuples including the absolute file name and file descriptor number. (Rt open_files(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRZstinetcC s|jj|S(sTReturn 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 | +------------+----------------------------------------------------+ (Rt connections(Rztkind((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR\scC s |jdk st|j|jdkr=tdnytj|j|Wntk r}|jtjkrtrt |jrt |j|j |j qt |_t|j|j n|jtjtjfkrt|j|j nnXdS(Nispreventing 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 0(RtAssertionErrorRRtkilltOSErrorterrnotESRCHR)R^RTRRRRRStEPERMtEACCESRU(RztsigR((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt _send_signals  cC str|j|nn|tjkr5|jjnO|ttdtttdtfkrx|jj|n t ddS(sSend 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(). t CTRL_C_EVENTtCTRL_BREAK_EVENTsPonly SIGTERM, CTRL_C_EVENT and CTRL_BREAK_EVENT signals are supported on WindowsN( R+RftsignaltSIGTERMRR_Rtobjectt send_signalR(RzRe((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRlscC s*tr|jtjn |jjdS(sSuspend process execution with SIGSTOP pre-emptively checking whether PID has been reused. On Windows this has the effect ot suspending all process threads. N(R+RfRitSIGSTOPRtsuspend(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRn/scC s*tr|jtjn |jjdS(sResume process execution with SIGCONT pre-emptively checking whether PID has been reused. On Windows this has the effect of resuming all process threads. N(R+RfRitSIGCONTRtresume(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRp:scC s*tr|jtjn |jjdS(sTerminate the process with SIGTERM pre-emptively checking whether PID has been reused. On Windows this is an alias for kill(). N(R+RfRiRjRR_(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt terminateEscC s*tr|jtjn |jjdS(sjKill the current process with SIGKILL pre-emptively checking whether PID has been reused. N(R+RfRitSIGKILLRR_(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR_PscC s8|dk r(|dk r(tdn|jj|S(sWait for process to terminate and, if process is a children of os.getpid(), also return its exit code, else None. 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(). is"timeout must be a positive integerN(RRRtwait(Rzttimeout((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRsZs N(FR|RRRRxRRRRRRRtpropertyRt contextlibtcontextmanagerRRRRRRRRRRRRRRR R+RR R R RRR\R RRRRRR-RRR R!RR,ReRdRRR@RARMRRNRZR\RfRlRnRpRqR_Rs(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR\s  /    C,    '               E \           cB sGeZdZdZdZdZdZdZddZ RS(s|A more convenient interface to stdlib subprocess.Popen class. It starts a sub process and deals with it exactly as when using subprocess.Popen class but in addition also provides all the properties and methods of psutil.Process class as a unified interface: >>> 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 >>> For method names common to both classes such as kill(), terminate() and wait(), psutil.Process implementation takes precedence. Unlike subprocess.Popen this class pre-emptively checks whether PID has been reused on send_signal(), terminate() and kill() so that you don't accidentally terminate another process, fixing http://bugs.python.org/issue6973. For a complete documentation refer to: http://docs.python.org/3/library/subprocess.html cO s2tj|||_|j|jjdtdS(NR(t subprocessR]t_Popen__subprocRRR(RzRR((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRxscC s#ttttttjS(N(tsortedRtdirR]Rx(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt__dir__scC s&t|jdr"|jjn|S(Nt __enter__(RRyR}(Rz((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR}scO st|jdr%|jj||S|jr>|jjn|jrW|jjnz|jrs|jjnWd|jXdS(Nt__exit__(RRyR~tstdouttclosetstderrtstdinRs(RzRR((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR~s   cC ssytj||SWnXtk rnytj|j|SWqotk rjtd|jj|fqoXnXdS(Ns!%s instance has no attribute '%s'(Rkt__getattribute__RRyR{R|(RzR((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs  cC sD|jjdk r|jjStt|j|}||j_|S(N(Ryt returncodeRtsuperR]Rs(RzRtR~((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRss   N( R|RRRxR|R}R~RRRs(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR]ps!     t_RlRnRpRqR_RsRRRRR,RR@RcC s ttj}|da|S(s&Return a list of current running PIDs.i(RzRR_R(R~((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR_s cC s@|dkrtS|dkr/tr/|tkStj|SdS(sReturn True if given PID exists in the current process list. This is faster than doing "pid in psutil.pids()" and should be preferred. iN(RR+R_RR^(R((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyR^s   c # sfd}d}tt}ttj}||}||}x|D]}||qWWt6tttjttj |j} WdQXx| D]\}} yg| dkr||VnI| j rdk r| j dd| _ n| Vn ||VWqtk r@||qtk r| dkr|tkry t|VWqtk rqXqqXqWdS(sReturn 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 sTt|}dk r6|jdd|_nt|t|j>> 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() c syy|jd|}Wntk r)nLX|dk sC|j ru||_j|dk ru|qundS(NRt(RsRVRRRR$(RRtR(tcallbacktgone(s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt check_gone^s    is*timeout must be a positive integer, got %sscallback %r is not a callableg?N( RRRtcallableRR-RtminR( tprocsRtRRRytalivetdeadlineRt max_timeout((RRs5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRa:s6$           cC sF|rtj}n tj}|dk rB|dkrBd}n|S(szReturn 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() iN(Rtcpu_count_logicaltcpu_count_physicalR(tlogicalR~((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRgs   cC s|stjStjSdS(sReturn 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(RRdt per_cpu_times(R((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRds RcC sEt|}trA|t|dd8}|t|dd8}n|S(sWGiven a cpu_time() ntuple calculates the total CPU time (including idle time). tguestit guest_nice(tsumR&R(ttimesttot((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt _cpu_tot_times   cC s3t|}||j8}|t|dd8}|S(slGiven a cpu_time() ntuple calculates the busy CPU time. We do so by subtracting all idle CPU times. tiowaiti(RtidleR(Rtbusy((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt_cpu_busy_times  cC s|j|jks$t||fg}xLtjjD]>}t||t||}td|}|j|q7Wtj|S(Ni(RDR^Rt scputimesRtmaxR(tt1tt2t field_deltastfieldt field_delta((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt_cpu_times_deltass$ cC sA|dk o|dk}|dk rC|dkrCtd|nd}|s|rqt}tj|nt}|dkrt}nta||tSg}|rtdt}tj|n$t}|dkrtdt}ntdtax3t|tD]"\}}|j |||qW|SdS(sReturn 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 >>> gis!interval is not positive (got %r)cS s_t||}t|}t|}y||d}Wntk rMdSXt|dSdS(Nidgi(RRRR3R4(RRt times_deltat all_deltat busy_deltat busy_perc((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyt calculate8s   RN( RRRdRR0t_last_cpu_timesRt_last_per_cpu_timestzipR(R5RR6RRR~ttot1R((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRes0%       cC sA|dk o|dk}|dk rC|dkrCtd|nd}|s|rqt}tj|nt}|dkrt}nta||tSg}|rtdt}tj|n$t}|dkrtdt}ntdtax3t|tD]"\}}|j |||qW|SdS(sSame 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(). gis!interval is not positive (got %r)cS sg}t||}t|}dtd|}xL|D]D}||}t|d}ttd|d}|j|q;Wtj|S(NgY@ig(RRRR4RRRR(RRRXRRtscaleRt field_perc((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs   RN( RRRdRR0t_last_cpu_times_2Rt_last_per_cpu_times_2RR(R5RR6RRR~RR((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRfms0       cC s tjS(sReturn CPU statistics.(RRh(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRhstcpu_freqc C stj}|r|Stt|}|dkr8dS|dkrL|dSd\}}}t}xV|D]N}||j7}tr|jdkrt }qhn||j7}||j 7}qhW||}|rd} } n||} ||} t j || | SdS(s9Return 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. iigN(ggg( RRRHRRRtcurrentR&RRRRtscpufreq( RR~R.tcurrstminstmaxstset_nonetcpuRtmin_tmax_((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRs.          t getloadavgcC stj}|ja|S(sReturn 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. (RRbRGRF(R~((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRbs5  cC s tjS(sReturn 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. (RRc(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRc/s cC s tj|S(sReturn disk usage statistics about the given *path* as a namedtuple including total, used and free space expressed in bytes plus the percentage usage. (RRo(R((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRoDscC s tj|S(s3Return 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. (RRn(tall((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyRnLs cC strtd|ni}tj|}|s>|r:iSdS|rVt|d}nttdtj}|rx*|j D]\}}||||tRLIMIT_MSGQUEUERt RLIMIT_NICEt RLIMIT_RTPRIOt RLIMIT_RTTIMEtRLIMIT_SIGPENDINGR@t_psutil_windowsRARBRCRDRERFRGRHRIRJRKRLRMRNRORPRQRtplatformt__all__textendt__extra__all__t __author__RXRRtnumRRWRR-RYR[RZRFRtreplacetcextRyRRRRuRORwRRRSRTRURVRRRRRRkR\R]RR{RRR_R^RtLockRR`RaRRgRRdRRRRRReRRRfRhRRRRbRcRoRnRmtpartialt cache_clearRiRjRkRlRRRRqRpRRRR|(((s5/usr/lib64/python2.7/site-packages/psutil/__init__.pyts                                         .   9          U&   K]          ZE  (   ;   / '   0        =