zoukankan      html  css  js  c++  java
  • 多进程队列的使用

    #_author:来童星
    #date:2019/12/17
    #多进程队列的使用
    from multiprocessing import Queue
    if __name__=='__main__':
    q=Queue(3)# 初始化一个Queue对象,最多可接收3条put消息
    q.put('消息1')
    q.put('消息2')
    print(q.full())
    q.put('消息3')
    print(q.full())
    try:
    q.put('消息4',True,2)
    except:
    print('消息队列已满,现有消息数量%d'%q.qsize())
    try:
    q.put_nowait()
    except:
    print('消息队列已满,现有消息数量%d' % q.qsize())
    #读取消息时,先判断消息队列是否为空
    if not q.empty():
    print('从队列中获取信息')
    for i in range(q.qsize()):
    print(q.get_nowait())
    #先判断消息队列是否已满,在写入
    if not q.full():
    q.put_nowait('消息4')
    运行结果:
    False
    True
    消息队列已满,现有消息数量3
    消息队列已满,现有消息数量3
    从队列中获取信息
    消息1
    消息2
    消息3
  • 相关阅读:
    论语学习系列(一)
    如何编译生成 dll
    Lua学习系列(二)
    Lua学习系列(一)
    Promise对象
    ... 扩展运算符
    class类
    proxy [ˈprɒksi] 代理
    HBuilder 打包流程
    Generator [ˈdʒenəreɪtə(r)] 函数结构
  • 原文地址:https://www.cnblogs.com/startl/p/12054289.html
Copyright © 2011-2022 走看看