#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. CentOS6 防火墙配置

    清空现有的规则 iptables -F iptables -P INPUT DROP iptables -I INPUT -m state --state RELATED , ESTABLISHED ...

  2. python基础-动态加载lazy_import(利用__import__)

    看了一天动态加载,普遍有这么几种方法,总结一下,由简入深,本文仅对查到的栗子们做个引用……省去你们大把查资料的时间= = 主要思想:把模块(文件)名.类名.方法名当成了变量 然后利用__import_ ...

  3. Spark2 ML包之决策树分类Decision tree classifier详细解说

    所用数据源,请参考本人博客http://www.cnblogs.com/wwxbi/p/6063613.html 1.导入包 import org.apache.spark.sql.SparkSess ...

  4. Java、JavaWeb中单元测试用到的测试方法

    写出的代码做单元测试时,一定要记住从三个方面出发:1.成功  2.异常  3 逻辑错误(即没有异常也可能程序运行出最后结果,可是呢?呵呵).这就是在做测试时我要牢记的三个方面,同时思维要严谨也即做事要 ...

  5. 地址转换函数:inet_aton & inet_ntoa & inet_addr和inet_pton & inet_ntop

    在Unix网络编程中,我们常用到地址转换函数,它将ASCII字符串(如"206.62.226.33")与网络字节序的二进制值(这个值保存在套接口地址结构中)间进行地址的转换. 1. ...

  6. HDU-2680 Choose the best route 单向边+反向dijkstra

    https://vjudge.net/problem/HDU-2680 题意:以起始点 终点 长度 给出一个图,已知可以从w个起点出发,求从任一起点到同一个终点s的最短路径.注意是单向边.m<1 ...

  7. HiveQL之Database相关操作

    1.Create Database(创建数据库语法) CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name [COMMENT database_ ...

  8. linux桌面与命令模式切换

    在图形下面按Ctrl+alt+F1(F2\F3\F4)进入命令模式 在命令模式下,按Ctrl+alt+F7回到图形,或登录用户输入startx进入图形!

  9. 第二课 eclipse安装

    下载并解压到C:\Program Files\eclipse 目录情况如图所示:

  10. windows dos命令大全

    windows dos命令大全 一.windows DOS命令概述 Windows的dos命令又是Windows的CMD命令.而cmd命令又是原来MS-DOS系统保留下来. DOS来源路径与配置对应的 ...