我继承了threading.Thread和bdb.Bdb。线程需要一个run函数来调用start函数,我需要使用Bdb.run函数。我如何引用Bdb的run函数,因为我无法使用self.run进行操作?我试过超级,但我显然没有使用它,我得到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)
答案 0 :(得分:4)
正如您在第22行调用Bdb的__init__
方法一样,您可以调用其run方法:
Bdb.run(self, self.statement)
super
仅在您不知道接下来需要调用哪个父类时才有用,并且您希望让Python的继承机制为您解决这个问题。在这里,您确切地知道要调用哪个函数Bdb.run
,所以只需调用它。