관리-도구
편집 파일: test_process.cpython-37.pyc
B �=�_7� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlZddlZddl Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZ ddlmZ dd lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl m"Z" ddl m#Z# ddl m$Z$ ddl m%Z% ddl m&Z& ddl m'Z' ddl m(Z( ddl m)Z) ddl m*Z* ddl m+Z+ ddl m,Z, ddl m-Z- ddl m.Z. dd l m/Z/ dd!l m0Z0 dd"l m1Z1 dd#l m2Z2 dd$l m3Z3 dd%l m4Z4 dd&l m5Z5 dd'l m6Z6 dd(l m7Z7 dd)l m8Z8 dd*l m9Z9 dd+l m:Z: dd,l m;Z; dd-l m<Z< G d.d/� d/e2�Z=e�r�e�>� dk�r�G d0d1� d1e=�Z?G d2d3� d3e2�Z@eAd4k�r�dd5lBmCZC eCeD� dS )6zTests for psutil.Process class.� N)�AIX)�BSD)�LINUX)�MACOS)�NETBSD)�OPENBSD)�OSX)�POSIX)�SUNOS)�WINDOWS)� open_text)�FileNotFoundError)�long)�PY3)�super)�APPVEYOR)� call_until)� CI_TESTING)�copyload_shared_lib)� create_exe)�GITHUB_ACTIONS)�GLOBAL_TIMEOUT)�HAS_CPU_AFFINITY)�HAS_ENVIRON)� HAS_IONICE)�HAS_MEMORY_MAPS)�HAS_PROC_CPU_NUM)�HAS_PROC_IO_COUNTERS)� HAS_RLIMIT)�HAS_THREADS)�mock)�process_namespace)�PsutilTestCase)�PYPY)� PYTHON_EXE)� reap_children)�retry_on_failure)�sh)�skip_on_access_denied)�skip_on_not_implemented)� ThreadTask)�unittest)�wait_for_pidc @ s� e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� Ze � e d�d d� �Zdd� Z dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Ze � e d!�d"d#� �Zd$d%� Ze � e d&�d'd(� �Ze � e d!�eed)�d*d+� ��Ze � e d!�e � e d,�d-d.� ��Ze � e d!�e � e d/�d0d1� ��Z!e � e" d!�d2d3� �Z#e � e" d!�d4d5� �Z$e � e" d!�d6d7� �Z%e � e" d!�d8d9� �Z&e � e" d!�d:d;� �Z'd<d=� Z(e � e d>�d?d@� �Z)e � e* d!�dAdB� �Z+e,� e-e.d)�e � e* d!�dCdD� ���Z/e,� dEdF� �Z0dGdH� Z1e � e2 d!�dIdJ� �Z3e � e2 d!�dKdL� �Z4dMdN� Z5dOdP� Z6dQdR� Z7dSdT� Z8e � e9dU�dVdW� �Z:dXdY� Z;e � e9dZ�d[d\� �Z<e � e=d]�e � e>d^�e � e9dU�d_d`� ���Z?e � e d&�dadb� �Z@e � e d&�dcdd� �ZAdedf� ZBdgdh� ZCdidj� ZDdkdl� ZEdmdn� ZFe � eG d!�dodp� �ZHe � eG d!�dqdr� �ZIe � eG d!�dsdt� �ZJe � eKdu�e � eLdv�dwdx� ��ZMe � eKdu�e � eLdv�dydz� ��ZNe � e d&�d{d|� �ZOeed)�e � eP�p�eQd}�d~d� ��ZRd�d�� ZSd�d�� ZTd�d�� ZUd�d�� ZVe,� d�d�� �ZWd�d�� ZXd�d�� ZYd�d�� ZZd�d�� Z[d�d�� Z\d�d�� Z]d�d�� Z^d�d�� Z_d�d�� Z`d�d�� Zad�d�� Zbe � e d&�d�d�� �Zce � e d&�d�d�� �Zde � e d&�d�d�� �Zed�d�� Zfe � eg d!�d�d�� �Zhe � eg d!�e � e d&�d�d�� ��Zid�S )��TestProcesszTests for psutil.Process class.c O s | j ||�}t�|j�S )N)�spawn_testproc�psutil�Process�pid)�self�args�kwargs�sproc� r6 �L/opt/alt/python37/lib64/python3.7/site-packages/psutil/tests/test_process.py�spawn_psprocN s zTestProcess.spawn_psprocc C s: t �� }| �|jt�� � | �t�� d|_W d Q R X d S )N�! )r/ r0 �assertEqualr1 �os�getpid�assertRaises�AttributeError)r2 �pr6 r6 r7 �test_pidT s zTestProcess.test_pidc C sJ | � � }|�� |�� }tr,| �|tj� n| �|tj � | �|� d S )N) r8 �kill�waitr r: �signal�SIGTERM�SIGKILL�assertProcessGone)r2 r? �coder6 r6 r7 � test_killZ s zTestProcess.test_killc C sJ | � � }|�� |�� }tr,| �|tj� n| �|tj � | �|� d S )N)r8 � terminaterB r r: rC rD rF )r2 r? rG r6 r6 r7 �test_terminated s zTestProcess.test_terminatec C sX t r tjntj}| �� }|�|� |�� }tr<| �||� n| �|| � | � |� d S )N) r rC rE rD r8 �send_signalrB r r: rF )r2 �sigr? rG r6 r6 r7 �test_send_signaln s zTestProcess.test_send_signalz not POSIXc C s� t j}| �� }tjdttjd�d�� | �t j |j|� W d Q R X | �� }tjdttjd�d�� | �t j |j|� W d Q R X d S )Nzpsutil.os.kill� )�side_effect)rC rD r8 r �patch�OSError�errnoZESRCHr= r/ � NoSuchProcessrK �EPERM�AccessDenied)r2 rL r? r6 r6 r7 �test_send_signal_mockedy s z#TestProcess.test_send_signal_mockedc C s� t ddg}| �|�}|�� }| �|d� | �|� t ddg}| j|tjd�}|�� }| �|d� | �|� t ddg}| �|�}|�� }| �|d� | �|� t dd g}| �|�}|�� }| �|d� | �|� d S ) Nz-c�passr z1 / 0)�stderr� zimport sys; sys.exit(5);� zimport os; os._exit(5);)r$ r8 rB r: rF � subprocess�PIPE)r2 �cmdr? rG r6 r6 r7 �test_wait_exited� s( zTestProcess.test_wait_exitedc C s� | � � }tr�|�tj� | jtj|jdd� |�tj � | jtj|jdd� |�tj � | �|�� tj � | �|�� tj � nd|�� | jtj|jdd� |� � | jtj|jdd� |�� | �|�� tj � | �|�� tj � d S )Ng����MbP?)�timeout)r8 r rK rC �SIGSTOPr= r/ �TimeoutExpiredrB �SIGCONTrD r: �suspend�resumerI )r2 r? r6 r6 r7 �test_wait_stopped� s zTestProcess.test_wait_stoppedc C s� | � � \}}| �tj|jd� | �tj|jd� |�� |�� |�� }|�� }trr| �|tj � | �|d � n| �|tj � | �|tj � d S )Ng{�G�z�?) �spawn_children_pairr= r/ ra rB rI r r: rC rD )r2 �child� grandchildZ child_retZgrandchild_retr6 r6 r7 �test_wait_non_children� s z"TestProcess.test_wait_non_childrenc C sH | � � }|�� | �tj|jd� | �tj|jd� | �t|jd� d S )Ng{�G�z�?r ���)r8 �namer= r/ ra rB � ValueError)r2 r? r6 r6 r7 �test_wait_timeout� s zTestProcess.test_wait_timeoutc C s� | � � }| �tj|jd� |�� t�� t }xBt�� |k rfy|�d�}P W q0 tjk rb Y q0X q0W | �d��t r�| � |tj � n| � |tj � | �|� d S )Nr r_ )r8 r= r/ ra rB rA �timer �failr r: rC rE rD rF )r2 r? Zstop_atrG r6 r6 r7 �test_wait_timeout_nonblocking� s z)TestProcess.test_wait_timeout_nonblockingc C s| t �� }|jdd� |jdd� x4td�D ](}|jd d�}| �|t� | �|d� q*W | �t�� |jdd� W d Q R X d S )Ng����MbP?)�interval�d g rj ) r/ r0 �cpu_percent�range�assertIsInstance�float�assertGreaterEqualr= rl )r2 r? �x�percentr6 r6 r7 �test_cpu_percent� s zTestProcess.test_cpu_percentc C s4 t jdd d��}t�� �� |js&t�W d Q R X d S )Nzpsutil.cpu_count)Zreturn_value)r rP r/ r0 rs �called�AssertionError)r2 �mr6 r6 r7 �test_cpu_percent_numcpus_none� s z)TestProcess.test_cpu_percent_numcpus_nonec C s� t �� �� }|jdks(|jdks(t|��|jdks:t|��|jdksLt|��trb|j dksbt|��x&|j D ]}t�dt� t||��� qjW d S )Ng z%H:%M:%S)r/ r0 � cpu_times�user�systemr| � children_user�children_systemr Ziowait�_fieldsrn �strftime� localtime�getattr)r2 �timesrk r6 r6 r7 �test_cpu_times� s zTestProcess.test_cpu_timesc C s� t �� �� d d� \}}t�� d d� \}}t||g�t||g� dkrZ| �d||f � t||g�t||g� dkr�| �d||f � d S )N� g�������?zexpected: %s, found: %s)r/ r0 r r; r� �max�minro )r2 � user_timeZkernel_time�utimeZktimer6 r6 r7 �test_cpu_times_2 s zTestProcess.test_cpu_times_2z not supportedc C sP t �� }|�� }| �|d� t �� dkr4| �|d� | �|�� tt �� �� d S )Nr rY )r/ r0 Zcpu_numrw � cpu_countr: �assertInrt )r2 r? �numr6 r6 r7 �test_cpu_num s zTestProcess.test_cpu_numc C sZ | � � }t�� }|�� }t|| �}|dkr@| �d|||f � t�dt�|�� �� d S )Nr� z'expected: %s, found: %s, difference: %sz%Y %m %d %H:%M:%S)r8 rn �create_time�absro r� r� )r2 r? �nowr� � differencer6 r6 r7 �test_create_time s zTestProcess.test_create_timez POSIX onlyc C s4 t �� �� }|d k r0tj�td��}| �||� d S )N�tty)r/ r0 �terminalr; �path�realpathr'