1

我继承自 threading.Thread 和 bdb.Bdb。线程需要一个 run 函数来调用 start 函数,我需要使用 Bdb.run 函数。由于无法使用 self.run 来引用 Bdb 的 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)
4

1 回答 1

4

正如您__init__在第 22 行调用 Bdb 的方法一样,您可以调用它的 run 方法:

Bdb.run(self, self.statement)

super仅当您不知道接下来需要调用哪个父类并且想让 Python 的继承机制为您解决问题时才有用。在这里,您确切地知道要调用哪个函数Bdb.run,所以只需调用它即可。

于 2012-04-16T18:38:28.693 回答