/
ilya.petrash
/
SimplePyScripts
Обзор
Документация
Войти
/
ilya.petrash
/
SimplePyScripts
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
psutil_example/process_management/process_control.py
56 строк
915 B
gil9red
Refactoring. Using black code style
02 июн 2023, 17:26
02 июн 2023, 17:26
ebd2521
Код
Авторство
О чём код?
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = "ipetrash" import time import threading def func(): i = 1 while True: print(threading.current_thread(), i) i += 1 time.sleep(1) if __name__ == "__main__": from multiprocessing import Process p = Process(target=func) p.start() print(p.pid) # pip install psutil import psutil process = psutil.Process(p.pid) print("is_running:", process.is_running()) print("Info:") from process_detail_info import print_info print_info(p.pid) print("\n") time.sleep(4) print("suspend on 3 seconds") process.suspend() time.sleep(3) print("resume") process.resume() print("terminate after 5 seconds") time.sleep(5) process.terminate() print("terminate") result_code = process.wait(timeout=3) print("result_code:", result_code)