从上的现有应用程序启动独立的应用程序会话和事件循环

2024-10-06 12:36:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望能够从现有的事件循环/反应器中派生出一个独立的事件循环/反应器。假设我在一个模块standaloneapps中有一个应用程序:

#in standaloneapps.py
class StandaloneApp(ApplicationSession):
    def runner(self, message):
        print(message)

    @inlineCallbacks
    def start_app(self):
        yield self.subscribe(self.runner, 'com.example.some_topic')

我希望能够从不同的应用程序启动此应用程序。示例:

from standaloneapps import StandaloneApp

class ApplicationStarter(ApplicationSession):

    @inlineCallbacks
    def onJoin(self, details):
        yield self.subscribe(self.start_app, 'com.example.startapp')

    def start_app(self, message):
        print('subscribing to app')
        new_runner = ApplicationRunner(url="ws://127.0.0.1:8080/ws", 
                                   realm="realm1") 
        runner.run(StandaloneApp)

我可以启动ApplicationStarter,但一旦发布事件'com.example.startapp',crossbar就会崩溃,出现异常builtins.Exception: not joined。你知道吗

也许这看起来是一个过于复杂的设置,但我正在尝试让一个应用程序订阅一个“app dispatcher”,它动态地启动新的应用程序,这些应用程序可能提前知道,也可能不知道。我希望新的应用程序在不同的事件循环上运行,以便保持隔离。你知道吗


Tags: selfcomapp应用程序messageexampledef事件