我可以幫助將此代碼從線程轉換爲Mutliprocess。 然後任何人都可以幫助轉換這個代碼usinf扭曲。線程與多進程vs Python中的扭曲
會不會有使用扭曲到Python的內上傳分貝
VS外部工具的增益。
import os, pyodbc, sys, threading, Queue
class WorkerThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
while 1:
try: # take a job from the queue
type = self.queue.get_nowait()
except Queue.Empty:
raise SystemExit
try:
cxn = pyodbc.connect('DSN=MySQL;PWD=MLML;Option=3')
csr = cxn.cursor()
# Inserts,update, CRUD
except:
# count = count +1
print 'DB Error', type
if __name__ == '__main__':
connections = 25
sml = ('A', 'B', 'C','D',)
# build a queue with tuples
queue = Queue.Queue()
for row in sml:
if not row or row[0] == "#":
continue
queue.put(row)
threads = []
for dummy in range(connections):
t = WorkerThread(queue)
t.start()
threads.append(t)
# wait for all threads to finish
for thread in threads:
thread.join()
sys.stdout.flush()
#csr.close()
#cxn.close()
print 'Finish'
您有沒有具體的問題,或者您真的只是想讓我們爲您編寫代碼? – nmichaels 2011-04-07 17:29:16
我無法讀取可變縮進的python-pseudo代碼。你能介意糾正你的縮進。甚至發佈一個工作示例? – MattH 2011-04-07 17:30:05
更新了代碼... – Merlin 2011-04-07 22:14:11