Python多线程简单例子
2017-05-01 18:17
423 查看
直接附上代码:
#!/usr/bin/python # coding:utf-8 import threading import time class Test(threading.Thread): def __init__(self): threading.Thread.__init__(self) # self._run_num = num def run(self): global count, mutex threadname = threading.currentThread().getName() # for x in xrange(0, int(self._run_num)): mutex.acquire() count += 1 mutex.release() print '线程信息名字:', threadname print '在这个线程中的编号: ', x print '累计和: ', count # time.sleep(1) global count, mutex threads = [] num = 4 count = 0 mutex = threading.Lock() for x in xrange(0, num): threads.append(Test()) for t in threads: t.start() for t in threads: t.join()
相关文章推荐
- python多线程简单例子
- 【多线程】python界面阻塞,白屏,not responding解决的简单例子
- 【多线程】python界面阻塞,白屏,not responding解决的简单例子
- Python3.5 多线程简单例子--threading.Thread
- 【多线程】python界面阻塞,白屏,not responding解决的简单例子
- 【多线程】python界面阻塞,白屏,not responding解决的简单例子
- python多线程简单例子
- Python 多线程简单例子
- python多线程 简单例子
- C#多线程简单例子
- python中使用状态机的简单例子---截取'/x00'之前的字符串
- Python多线程 简明例子
- 简单使用scipy.weave混合使用Python和C++代码的简单例子
- python 多线程例子
- Python多线程 简明例子
- 学习简单的python----最简单的python GUI例子 1
- linux 多线程 最简单 例子 代码
- Python简单经典的例子!
- 多线程和委托简单例子
- Python多线程 简明例子