python 多线程例子
来源:互联网 发布:数组去重js算法实现 编辑:程序博客网 时间:2024/05/22 15:59
#!/usr/bin/env python# encoding: utf-8import sysimport threadimport timeimport threadingreload(sys).setdefaultencoding('UTF-8')import osimport logging"""@version: @author: @license: @contact: @site: @software: PyCharm@file: thread_test.py@time: 2016/11/24 10:10"""def func(): passclass Main(): def __init__(self): passdef print_time(threadName, delay): count = 0 while count < 5 : time.sleep(delay) count += 1 print "%s: %s" % (threadName, time.ctime(time.time()))# 创建两个线程# try:# thread.start_new_thread(print_time, ("Thread-1", 2))# thread.start_new_thread(print_time, ("Thread-2", 4))## except:# print 'error'## while 1:# passclass myThread(threading.Thread): def __init__(self, threadID, name, counter): threading.Thread.__init__(self) self.threadID = threadID self.name = name self.counter = counter def run(self): print 'start' print_time(self.name, self.counter, 5) print 'end'def print_time(threadName, delay, counter): while counter: print "%s: %s" % (threadName, time.ctime(time.time())) time.sleep(delay) counter -= 1# 创建新线程thread1 = myThread(1, "Thread-1", 10)thread2 = myThread(2, "Thread-2", 2)# 开启线程thread1.start()thread2.start()if __name__ == '__main__': pass
0 0
- Python多线程 简明例子
- Python多线程 简明例子
- Python多线程 简明例子
- Python多线程 简明例子
- python 多线程例子
- Python多线程 简明例子
- Python 多线程简单例子
- Python多线程 简明例子
- Python多线程 简明例子
- python多线程简单例子
- python 多线程例子
- Python多线程简单例子
- Python多线程小例子
- python多线程 简单例子
- Python多线程锁例子
- Python多线程Socket程序例子
- python多线程编程例子实验
- python中多线程的一个例子
- Nuttx配置和编译
- 获取两个字符串的最大相同子串
- 关于Android的log日志
- 谷歌DeepMind识别算法新突破:一眼“看清”物体
- fragment生命周期之Onstart();
- python 多线程例子
- log4cplus日志工具样例
- 适配器模式(Adapter Pattern)
- AFNetwork网络数据解析的方式
- 关于百度“判罚”的谣言
- 【Prim算法和Kruskal算法的验证】
- Rancher网络全解读
- STL中各种容器的简单特点
- Eclipse如何解决启动慢?