Python Twisted makeService()异步

Python Twisted makeService()异步,python,asynchronous,plugins,twisted,Python,Asynchronous,Plugins,Twisted,我需要创建一个MultiService,在twisted插件中异步加载,有什么方法可以实现吗 以下是我迄今为止所做的工作: app/plugins.py class Options(usage.Options): synopsis = '[options]' longdesc = ( 'Starts app modules services. The modules must ' 'be configured and enabled for the

我需要创建一个
MultiService
,在twisted插件中异步加载,有什么方法可以实现吗

以下是我迄今为止所做的工作:

app/plugins.py

class Options(usage.Options):
    synopsis = '[options]'
    longdesc = (
        'Starts app modules services. The modules must '
        'be configured and enabled for the current server '
        'before being started. To see the list installed modules '
        'use the --list switch.')
    optFlags = [['list', 'l', 'Display the list of installed modules.']]


def makeService(options):
    from twisted.internet import reactor
    debug = options['debug']
    return app.ModuleService.load(reactor)
TestService = ServiceMaker(
    'test',
    'app.plugins',
    'Test service.',
    'test')
class ModuleService(service.MultiService):
    def __init__(self, reactor=None):

        # Twisted old style classes
        service.MultiService.__init__(self)

        if reactor is None:
            from twisted.internet import reactor
        self._reactor = reactor

    @classmethod
    @defer.inlineCallbacks
    def load(cls, reactor=None):

        modules = yield get_modules()

        service = cls(reactor)

        for module in modules:
            # module tcp server
            mod_endpoint = endpoints.TCP4ServerEndpoint(reactor, module.port)
            module_service = internet.StreamServerEndpointService(
                mod_endpoint,
                pb.PBServerFactory(spread.RunnerServer()))
            module_service.setServiceParent(service)

        defer.returnValue(service)
twisted/plugins/app_plugins.py

class Options(usage.Options):
    synopsis = '[options]'
    longdesc = (
        'Starts app modules services. The modules must '
        'be configured and enabled for the current server '
        'before being started. To see the list installed modules '
        'use the --list switch.')
    optFlags = [['list', 'l', 'Display the list of installed modules.']]


def makeService(options):
    from twisted.internet import reactor
    debug = options['debug']
    return app.ModuleService.load(reactor)
TestService = ServiceMaker(
    'test',
    'app.plugins',
    'Test service.',
    'test')
class ModuleService(service.MultiService):
    def __init__(self, reactor=None):

        # Twisted old style classes
        service.MultiService.__init__(self)

        if reactor is None:
            from twisted.internet import reactor
        self._reactor = reactor

    @classmethod
    @defer.inlineCallbacks
    def load(cls, reactor=None):

        modules = yield get_modules()

        service = cls(reactor)

        for module in modules:
            # module tcp server
            mod_endpoint = endpoints.TCP4ServerEndpoint(reactor, module.port)
            module_service = internet.StreamServerEndpointService(
                mod_endpoint,
                pb.PBServerFactory(spread.RunnerServer()))
            module_service.setServiceParent(service)

        defer.returnValue(service)
app.py

class Options(usage.Options):
    synopsis = '[options]'
    longdesc = (
        'Starts app modules services. The modules must '
        'be configured and enabled for the current server '
        'before being started. To see the list installed modules '
        'use the --list switch.')
    optFlags = [['list', 'l', 'Display the list of installed modules.']]


def makeService(options):
    from twisted.internet import reactor
    debug = options['debug']
    return app.ModuleService.load(reactor)
TestService = ServiceMaker(
    'test',
    'app.plugins',
    'Test service.',
    'test')
class ModuleService(service.MultiService):
    def __init__(self, reactor=None):

        # Twisted old style classes
        service.MultiService.__init__(self)

        if reactor is None:
            from twisted.internet import reactor
        self._reactor = reactor

    @classmethod
    @defer.inlineCallbacks
    def load(cls, reactor=None):

        modules = yield get_modules()

        service = cls(reactor)

        for module in modules:
            # module tcp server
            mod_endpoint = endpoints.TCP4ServerEndpoint(reactor, module.port)
            module_service = internet.StreamServerEndpointService(
                mod_endpoint,
                pb.PBServerFactory(spread.RunnerServer()))
            module_service.setServiceParent(service)

        defer.returnValue(service)

所以我的问题是多服务是异步加载的,因此不能在
makeService
函数中使用,有人可以帮助我吗?

twisted中的服务不应该异步启动。服务启动在reactoru启动之前完成。您应该更改您的应用程序体系结构。我目前正在研究如何:D