我有一個類線程是這樣的:多線程參數路過
import threading, time
class th(threading.Thread):
def run(self):
print "Hi"
time.sleep(5)
print "Bye"
現在讓我們說,我想「沉睡」不同的每一次,所以我嘗試:
import treading, time
class th(threading.Thread, n):
def run(self):
print "Hi"
time.sleep(n)
print "Bye"
它不工作,它給我留言:
組參數必須是無,現在
那麼,如何在運行中傳遞參數?
注:我在班上像另一個函數做的:
import treading, time
class th(threading.Thread):
def run(self):
print "Hi"
time.sleep(self.n)
print "Bye"
def get_param(self, n):
self.n = n
var = th()
var.get_param(10)
var.start()
'selfn'應該是'self.n'。 – user2357112
謝謝。我沒有考慮它,這非常有幫助。 –