代碼片段如下
from socket import *
import sys
from threading import Thread,Lock
class mythread(Thread):
def __init__(self, fun ,args):
Thread.__init__(self)
self.fun = fun
self.args = args
def run(self):
apply(self.fun, self.args)
報出錯誤如下
Traceback (most recent call last):
File "D:\anaconda3\lib\threading.py", line 926, in _bootstrap_inner
self.run()
報出錯誤原因
python2中apply()在python3中變成了fun()
修改代碼如下
from socket import *
import sys
from threading import Thread,Lock
class mythread(Thread):
def __init__(self, fun ,args):
Thread.__init__(self)
self.fun = fun
self.args = args
def run(self):
self.fun(*self.args)
關注我,帶你一起寫bug
warning :未經授權,不得轉載
有問題的小夥伴請在下方留言,喜歡就點個贊吧