Python -进程

进程编号:

1.当前执行的代码的name : multiprocessing.current_process ( )

2.当前的进程编号 : multiprocessing.current_process() . pid

3.父进程编号:os.getppid ( )

4.当前的进程编号+ 父进程编号 :multiprocessing.current_process() . pid , os.getppid ()

print("当前执行的代码的name :",multiprocessing.current_process ())

print ("当前的进程编号 :", multiprocessing.current_process().pid)

print ("父进程编号:", os.getppid())

print("当前的进程编号+ 父进程编号 :",multiprocessing.current_process() pid   os.getppid())

当前执行的代码的 name : <_MainProcess(MainProcess, started)>
当前的进程编号 : 6748
父进程编号: 3496
当前的进程编号+ 父进程编号 : 6748 3496


消息队列:

消息队列 上限 : q = multiprocessing . Queue ( 3 )
添加内容: q. put( “内容”)
加载内容: q . get( )


  • Queue.qsize():返回当前队列包含的消息数量;
  • Queue.empty():如果队列为空,返回True,反之False , 注意这个操作是不可靠的。
  • Queue.full():如果队列满了,返回True,反之False;

c = q.full()
print("是否满了:",  c )   


time.sleep(0.01)
d = q.empty()
print("是否空了:"  , d )


if q.qsize( ) ==  0 :
    print(  "满了" )
else:
    print(  "没"   )

这里写图片描述

猜你喜欢

转载自blog.csdn.net/haohao143/article/details/82465408
今日推荐