python启动多进程并查看子进程信息

查看python 子进程的信息:

import multiprocessing
import psutil
import time
import os

def worker(file_info, interval):
    file_info_cp = file_info
    this_thread = multiprocessing.current_process()
    print('worker %s: PID=%s' % (this_thread.name, this_thread.pid))
    tp = psutil.Process(this_thread.pid)
    print('worker %s: memory_info=%s' % (this_thread.name, tp.memory_info().rss/1024/1024))
    n = 1000000000
    while n > 0:
        print("%s The time is {0}".format(time.ctime()) % this_thread.name)
        time.sleep(interval)
        n -= 1
def make_multi_process():
    with open('test.txt', mode='r', encoding='utf8') as f:
        file_info = f.read()
    print('sss b')
    worker_num = 2
    interval = 3
    this_thread = multiprocessing.current_process()
    tp = psutil.Process(this_thread.pid)
    print('main worker %s: PID=%s' % (this_thread.name, this_thread.pid))
    print('main worker %s: memory_info=%s' % (this_thread.name, tp.memory_info().rss / 1024 / 1024))
    for i in range(worker_num):
        entity_profiler_proc = multiprocessing.Process(target=worker, args=(file_info, interval), name='M_thread_%d' % i)
        #entity_profiler_proc.daemon = True
        entity_profiler_proc.start()
    print('sss e')


if __name__ == "__main__":
    make_multi_process()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值