#coding=utf-8
import multiprocessing as mp
import time

def consumer(cond):
    with cond:
        print "consumer before wait"
        cond.wait()
        print "consumer after wait"

def producer(cond):
    with cond:
        print "producer before notifyAll"
        cond.notify_all()
        print "producer after notifyAll"

if __name__ =='__main__':
    condition=mp.Condition()
   
    p1=mp.Process(name='p1',target=consumer,args=(condition,))
    p2=mp.Process(name='p2',target=consumer,args=(condition,))
    p3=mp.Process(name='p3',target=producer,args=(condition,))
   
    p1.start()
    time.sleep(2)
    p2.start()
    time.sleep(2)
    p3.start()

c:\Python27\Scripts>python task_test.py
consumer before wait
consumer before wait
producer before notifyAll
producer after notifyAll
consumer after wait
consumer after wait

python进程同步,condition例子的更多相关文章

  1. python多线程简单例子

    python多线程简单例子 作者:vpoet mail:vpoet_sir@163.com import thread def childthread(threadid): print "I ...

  2. Python 发邮件例子

    Python 发邮件例子 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019-04-23 16:12:33 # @Autho ...

  3. python gevent使用例子

    python gevent使用例子 from gevent.pool import Pool POOL_SIZE = 100 def process(func, param1_list, param2 ...

  4. Python random模块 例子

    最近用到随机数,就查询资料总结了一下Python random模块(获取随机数)常用方法和使用例子. 1.random.random  random.random()用于生成一个0到1的随机符点数: ...

  5. python entry points 例子

    pbr的介绍不多,http://ju.outofmemory.cn/entry/156745 $ mkdir entry_test; cd entry_test; git init $ mkdir  ...

  6. Python练手例子(10)

    55.学习使用按位取反~. 程序分析:~0=1; ~1=0; (1)先使a右移4位. (2)设置一个低4位全为1,其余全为0的数.可用~(~0<<4) (3)将上面二者进行&运算. ...

  7. Python练手例子(4)

    16.一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程找出1000以内的所有完数. 程序分析:请参照程序Python 100例中的第14个例子 #py ...

  8. Python练手例子(3)

    13.打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数",因为153=1 ...

  9. Python 简单soket例子

      简单的soket例子 Python 2.0 客户端服务端传输 1.可发字符串,可发字节 bys类型 Python 3.0 客户端服务端传输 1.只能发bys,比特流的类型. 2.bys类型只能接收 ...

随机推荐

  1. Zabbix监控虚拟主机告警Lack of free swap space on Zabbix server解决办法

    Zabbix监控虚拟机的时候有时候会报一下告警 是因为Zabbix监控没有考虑虚拟主机的交换空间情况 解决办法修改配置

  2. 天梯赛 大区赛 L3-014.周游世界 (Dijkstra)

    L3-014. 周游世界 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 周游世界是件浪漫事,但规划旅行路线就不一定了-- 全世 ...

  3. zero-shot learning(ps:每天演好一个情绪稳定的成年人)

    my paper~~ 1.(DAP,IAP)Learning To Detect Unseen Object Classes by Between-Class Attribute Transfer 2 ...

  4. MySQL复制日常维护与管理

    一.复制一些常见设置 1.mysql复制启动时参数: mysql启动时的参数包括:master_host,master_port,master_user,master_password,master_ ...

  5. C++创建窗口程序初步

    写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...

  6. ElasticSearch报 EsThreadPoolExecutor[search, queue capacity = 1000, org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor@c0efba

    ElasticSearch报以下错误的解决办法: "type": "es_rejected_execution_exception", "reason ...

  7. 20144306《网络对抗》MAL_PC平台逆向破解_Advanced

    PC平台逆向破解_Advanced 一.注入shellcode并执行 1.什么是shellcode? shellcode顾名思义就是一段为了获取交互式shell的机器指令,是用来发送到服务器利用特定漏 ...

  8. 读取Excel列,转换为String输出(Java实现)

    需要导入的jar包 具体实现 public class ColumnToString { public static void main(String[] args) { new ColumnToSt ...

  9. jquery ajax contentType设置

    默认get方法没有contentType,post方法的contentType为:application/x-www-form-urlencoded; charset=UTF-8 (1) 设置成app ...

  10. Heavy Transportation---poj1797

    求(Dijkstra算法,求每条路径上的最小值 的最大值)和青蛙的那题类似:   #include<iostream> #include<stdio.h> #include&l ...