python高效编程技巧11(如何使用多线程)
来源:互联网 发布:淘宝送货上门怎么设置 编辑:程序博客网 时间:2024/06/05 00:40
#!/usr/bin/env python# -*- coding:utf-8 -*-# 使用线程的两种方式from threading import Thread# ======1、直接使用Thread======def say_hello(number): print number print "hello world"t = Thread(target=say_hello, args=(1,))t.start()print "this is the main thread"# ======2、使用类来实现多线程======class myThread(Thread): def __init__(self, name): # 要调用分类的构造器 Thread.__init__(self) self.name = name def run(self): print "执行了方法。。。。"my_thread = myThread("Tom")my_thread.start()# 如果my_thread使用了my_thread方法,表示这个这里会阻塞,直到my_thread线程运行完以后,才会执行一下的逻辑my_thread.join()print "这是主线程"
阅读全文
0 0
- python高效编程技巧11(如何使用多线程)
- python高效编程技巧14(如何使用线程池)
- python高效编程技巧9(如何读写csv文件)
- python高效编程技巧10(如何读写json)
- Python高效编程技巧
- Python高效编程技巧
- Python高效编程技巧
- Python高效编程技巧
- Python高效编程技巧
- Python高效编程技巧
- Python高效编程技巧
- Python高效编程技巧
- Python高效编程技巧
- Python高效编程技巧
- [转载]Python高效编程技巧
- python高效编程技巧3(如何统计序列中元素出现的频率)
- python高效编程技巧5(如何快速找到多个字典中的公共键)
- python高效编程技巧6(如何实现用户的历史记录功能)
- 声明和定义
- ASP.NET状态管理之六(缓存Cache)
- jmx实例
- 用myeclipse的Hibernate 反向引擎 生成 数据库的 entity
- ACboy needs your help hdu 分组背包问题
- python高效编程技巧11(如何使用多线程)
- jmx 总结
- 安装 awstats
- docker跨主机访问-实验笔记
- MYSQL性能优化的最佳20+条经验
- linux步步为营(1)--理论基础
- fetch = FetchType.EAGER 作用
- Hibernate 的 join
- linux步步为营(2)--常用配置 & shell