我是从threading.Thread和bdb.Bdb继承的。线程需要start函数才能调用run函数,而我需要使用Bdb.run函数。由于我无法使用self.run来执行Bdb的运行功能?我尝试了 super ,但我显然没有使用该权利,我得到了TypeError:必须是类型,而不是classobj。
import sys
import os
import multiprocessing
import threading
import bdb
from bdb import Bdb
from threading import Thread
from el_tree_o import ElTreeO, _RUNNING, _PAUSED, _WAITING
from pysignal import Signal
class CommandExec(Thread, Bdb):
'''
Command Exec is an implementation of the Bdb python class with is a base
debugger. This will give the user the ability to pause scripts when needed
and see script progress through line numbers. Useful for command and
control scripts.
'''
def __init__(self, mainFile, skip=None):
Bdb.__init__(self,skip=skip)
Thread.__init__(self)
# need to define botframe to protect against an error
# generated in bdb.py when set_quit is called before
# self.botframe is defined
self.botframe = None
# self.even is used to pause execution
self.event = threading.Event()
# used so I know when to start debugging
self.mainFile = mainFile
self.start_debug = 0
# used to run a file
self.statement = ""
def run(self):
self.event.clear()
self.set_step()
super(bdb.Bdb,self).run(self.statement)
最佳答案
就像在第22行调用Bdb的__init__
方法一样,您也可以调用其run方法:
Bdb.run(self, self.statement)
super
仅在您不知道接下来需要调用哪个父类并且希望让Python的继承机制为您解决该问题时才有用。在这里,您确切地知道要调用哪个函数Bdb.run
,因此只需调用它即可。