Created
May 30, 2014 11:26
-
-
Save LeZuse/7467a8c0c4b2e18273ee to your computer and use it in GitHub Desktop.
Python thread example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import os | |
| import re | |
| import time | |
| import sys | |
| import thread | |
| from threading import Thread | |
| class thread_it(Thread): | |
| def __init__ (self,param): | |
| Thread.__init__(self) | |
| self.param = param | |
| def run(self): | |
| mutex.acquire() | |
| try: | |
| output.append(self.param) | |
| except: | |
| pass | |
| mutex.release() | |
| threads = [] | |
| output = [] | |
| mutex = thread.allocate_lock() | |
| for j in range(0, 10): | |
| current = thread_it(j) | |
| threads.append(current) | |
| current.start() | |
| for t in threads: | |
| t.join() | |
| print output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment