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):
        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 :未經授權,不得轉載

有問題的小夥伴請在下方留言,喜歡就點個贊吧

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章