Skip to content

Instantly share code, notes, and snippets.

@LeZuse
Created May 30, 2014 11:26
Show Gist options
  • Select an option

  • Save LeZuse/7467a8c0c4b2e18273ee to your computer and use it in GitHub Desktop.

Select an option

Save LeZuse/7467a8c0c4b2e18273ee to your computer and use it in GitHub Desktop.
Python thread example
#!/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