Python, Call a class function from another class

試著忘記壹切 提交于 2019-12-06 16:09:31

Pass the class instance of BroadcastServerFactory to be called to the class instance that calls it process on creation

class process(threading.Thread):
    def __init__(self, buffer3m, broadcast_server_factory):
        threading.Thread.__init__(self)
        self.setDaemon(True)
        self.buffer3 = buffer3

        self.factory = broadcast_server_factory

    def run(self):
        self.factory.broadcast("I don't know what I'm doing!")

and then call it (it's assigned as self.factory in the run statement. I can't see where you create a process class in your __main__ but it will be created with something like

 p = process(buffer, factory)

Aside: Using capital letters for class names is considered good form in python process -> Process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!