您好我正在嘗試調用當前正在運行的self.x.run()。此代碼已安排,不能更改訂購如何在python中調用當前正在運行的方法/類
class SocketWatcher(Thread):
.....
def checker(self):
# here I want to call the currently running self.x.run() that has been
# created in the mainPlayer class..
class counterTicket(Thread):
....
def increment(self):
class mainPlayer:
....
def run(self, obj):
self.x = counterTicket()
self.x.increment()
是否有可能?
我只想調用一個在mainPlayer類中調用的運行方法。但我不知道如何去做。如果我要實例化counterTicket類來調用SocketWatcher類的increment(),看起來它會創建新的counterTicket類,而不是mainPlayer類正在運行的counterTicket類
你能澄清一下嗎?這並不明顯,你期待什麼。 – FatalError
你有沒有試過在你的'def run'開頭設置一個全局變量等於'self'或'self.x'的(顯而易見的)解決方案,然後在函數返回之前將該變量設置爲'None'?我相當肯定你可以用你的其他線程以這種方式拉取當前運行的方法/類實例的引用。 – Shashank