进程间通信IPC机制

#管道
#队列=管道+锁
from multiprocessing import Queue

# q=Queue()
# q.put(['first',])
# q.put({'x':2})
# q.put(3)
# # q.put(4)
#
# print(q.get())
# print(q.get())
# print(q.get())
# print(q.get())

# 了解:
q=Queue(3)
# q.put(['first',],block=True,timeout=3)
# q.put({'x':2},block=True,timeout=3)
# q.put(3,block=True,timeout=3)
# q.put(4,block=True,timeout=3)

q.put_nowait(1) #q.put(1,block=False)
q.put_nowait(2)
q.put_nowait(3)
# q.put_nowait(4)

# print(q.get(block=True,timeout=3))
# print(q.get(block=True,timeout=3))
# print(q.get(block=True,timeout=3))
# print(q.get(block=True,timeout=3))

print(q.get_nowait()) #q.get(block=false)
print(q.get_nowait()) #q.get(block=false)
print(q.get_nowait()) #q.get(block=false)
print(q.get_nowait()) #q.get(block=false)

 

posted @ 2020-09-10 23:23  xuqidong  阅读(131)  评论(0编辑  收藏  举报