python队列join
如果要让一个任务队列按照顺序进行,则必须使用join,代码如下:
'''
Created on Dec 23, 2013 @author: long
'''
import threading
from threading import Thread
import time class Thread1(Thread):
'''
classdocs
''' def __init__(self,thread_name):
'''
Constructor
'''
Thread.__init__(self,name=thread_name) def run(self):
'''
run method
'''
count = 0
while True:
print ('thread--',self.getName(),",count:",count)
time.sleep(0.5)
count = count + 1
if count > 10:
break def main(): for y in range(1, 3):
thread1 = Thread1('longthread' + str(y))
thread1.start()
if thread1.isAlive():
thread1.join() for i in range(50):
print ('main:', i) if __name__ == "__main__":
main()
结果是先执行名为'longthread1',再'longthread2',再是主进程,所以thread1.join()的意思是等thread1执行完,再去执行其他线程。
python队列join的更多相关文章
- Python队列及在微信机器人中的应用
本文来源于i春秋学院,未经允许严禁转载. 最近打算更新微信机器人,发现机器人的作者将代码改进了很多,但去掉了sqlite数据库,需要自己根据需求设计数据库,跟作者沟通得到的建议是为了防止消息并发导致数 ...
- Python队列服务 Python RQ Functions from the __main__ module cannot be processed by workers.
在使用Python队列服务 Python RQ 时候的报错: Functions from the __main__ module cannot be processed by workers. 原因 ...
- python中join()函数的使用方法
函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下: join(): 连接字符串数组.将字符串.元组.列表中的元素以指定的字 ...
- Python中join()函数方法
函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下: join(): 连接字符串数组.将字符串.元组.列表中的元素以指定的字 ...
- Python中join函数和os.path.join用法
Python中有join和os.path.join()两个函数,具体作用如下: join:连接字符串数组.将字符串.元组.列表中的元素以指定的字符(分隔符)连接生成一个新的字符串 os.path.jo ...
- Python MySQL Join
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- (转)python中join()方法
原文:http://blog.csdn.net/weixin_40475396/article/details/78227747 函数:string.join() Python中有join()和os. ...
- 《python》join、守护进程、锁/信号量/事件、进程队列
一.multiprocess.process模块 1.join方法 阻塞主进程,等待子进程执行完毕再放开阻塞 import time import random from multiprocessin ...
- python队列Queue
Queue Queue是python标准库中的线程安全的队列(FIFO)实现,提供了一个适用于多线程编程的先进先出的数据结构,即队列,用来在生产者和消费者线程之间的信息传递 基本FIFO队列 clas ...
随机推荐
- android中的Handler和Runnable
最近在做一个项目,在网络请求时考虑用Handler进行处理,然后就研究了一下Handler和Runnable 首先在看一下java中的Runnable The Runnable interface s ...
- javaScript特效
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- C#解leetcode:119. Pascal's Triangle II
题目是: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return ...
- C#之—委托
(1)定义委托:(百度百科样例,只有写了才有收获) namespace Entrust { public delegate void GreetingDelegate(string name); // ...
- ThinkPHP学习 volist标签高级应用之多重嵌套循环、隔行变色(转)
Action代码: public function index(){ $prod = I("get.prod_en"); $id = I("get.id", 0 ...
- eclipse[日文版] 的SVN 上传步骤
可能有些朋友在日企上班,肯定要用到SVN,可是一般就下载和更新,没有用到上传 这里来介绍下上传 1.项目右键 2.点击Share Project 3.点击SVN下一步 4.选择你的上传的服务器地址 5 ...
- 通过ip地址获取当前地理位置
1. 使用接口的方式: 这种方式是相对稳定,而且提供的数据相对稳定,提供接口的地方很多,大家可以参照 http://www.hujuntao.com/api/the-ip-address-api-a ...
- B/S 獲取客戶端Mac地址
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx. ...
- SVN global ignore pattern for c#
*.resharperoptions Web_Data log */[Bb]in [Bb]in */obj obj */TestResults TestResults *.svclog Debug ...
- C++拾遗(三)关于复合类型
数组相关 初始化只能在定义的时候使用,不能把数组赋给另一个数组. 初始化可以提供比元素数目少的初值,其它元素将被置为0. 字符char数组只有在以\0结尾时才是一个字符串.sizeof()返回数组的长 ...