无法为thespian演员添加伐木处理程序

发布于 2025-01-18 16:42:33 字数 3733 浏览 2 评论 0原文

然而,尝试在 Thespian(演员模型系统)中设置并行化时,我收到错误,并且关于如何解决该问题的文档或资源为 0。

class Init:
    def __init__(self):
        pass

class Test(ActorTypeDispatcher):
    ...

class FooBar(ActorTypeDispatcher):
    def receiveMsg_Init(self, message, sender):
        self.createActor(Test)

class actorLogFilter(logging.Filter):
    def filter(self, logrecord):
        return 'actorAddress' in logrecord.__dict__


class notActorLogFilter(logging.Filter):
    def filter(self, logrecord):
        return 'actorAddress' not in logrecord.__dict__

logcfg = {'version': 1,
          'formatters': {
              'normal': {'format': '%(levelname)-8s %(message)s'},
              'actor': {'format': '%(levelname)-8s %(actorAddress)s => %(message)s'}},
          'filters': {'isActorLog': {'()': actorLogFilter},
                      'notActorLog': {'()': notActorLogFilter}},
          'handlers': {'h1': {'class': 'logging.FileHandler',
                              'filename': 'example.log',
                              'formatter': 'normal',
                              'filters': ['notActorLog'],
                              'level': logging.INFO},
                       'h2': {'class': 'logging.FileHandler',
                              'filename': 'example.log',
                              'formatter': 'actor',
                              'filters': ['isActorLog'],
                              'level': logging.INFO}, },
          'loggers': {'': {'handlers': ['h1', 'h2'], 'level': logging.DEBUG}}
}


if __name__ == "__main__":
    system = ActorSystem("multiprocQueueBase", logDefs=logcfg)
    main = system.createActor(FooBar)
    system.tell(main, Init())

错误

ERROR  ActorAddr-Q.ThespianQ.b => Actor __main__.Main @ ActorAddr-Q.ThespianQ.b retryable exception on message <definitions.Init object at 0x7f9c82283af0>
Traceback (most recent call last):

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 642, in configure
    self.configure_root(root)

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 802, in configure_root
    self.common_logger_config(root, config, incremental)

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 783, in common_logger_config
    logger.removeHandler(h)

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/system/logdirector.py", line 183, in removeHandler
    raise NotImplementedError('Cannot add logging handlers for Thespian Actors')

NotImplementedError: Cannot add logging handlers for Thespian Actors

Traceback (most recent call last):

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/system/actorManager.py", line 164, in _handleOneMessage
    actor_result = self.actorInst.receiveMessage(msg, envelope.sender)

  File "main.py", line 98, in receiveMessage
    self.init()

  File "main.py", line 60, in init
    a = elf.createActor(Test)

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/actors.py", line 637, in __init__
    systemBase = self._startupActorSys(

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/actors.py", line 662, in _startupActorSys
    systemBase = thespian.system \

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/system/simpleSystemBase.py", line 257, in __init__
    if logDefs is not False: dictConfig(logDefs or defaultLoggingConfig)

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 808, in dictConfig
    dictConfigClass(config).configure()

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 644, in configure
    raise ValueError('Unable to configure root '

ValueError: Unable to configure root logger

Trying to set up parallelization in Thespian (Actor-Model system), however, I am getting an error and there is 0 documentation or resources on how to solve it.

class Init:
    def __init__(self):
        pass

class Test(ActorTypeDispatcher):
    ...

class FooBar(ActorTypeDispatcher):
    def receiveMsg_Init(self, message, sender):
        self.createActor(Test)

class actorLogFilter(logging.Filter):
    def filter(self, logrecord):
        return 'actorAddress' in logrecord.__dict__


class notActorLogFilter(logging.Filter):
    def filter(self, logrecord):
        return 'actorAddress' not in logrecord.__dict__

logcfg = {'version': 1,
          'formatters': {
              'normal': {'format': '%(levelname)-8s %(message)s'},
              'actor': {'format': '%(levelname)-8s %(actorAddress)s => %(message)s'}},
          'filters': {'isActorLog': {'()': actorLogFilter},
                      'notActorLog': {'()': notActorLogFilter}},
          'handlers': {'h1': {'class': 'logging.FileHandler',
                              'filename': 'example.log',
                              'formatter': 'normal',
                              'filters': ['notActorLog'],
                              'level': logging.INFO},
                       'h2': {'class': 'logging.FileHandler',
                              'filename': 'example.log',
                              'formatter': 'actor',
                              'filters': ['isActorLog'],
                              'level': logging.INFO}, },
          'loggers': {'': {'handlers': ['h1', 'h2'], 'level': logging.DEBUG}}
}


if __name__ == "__main__":
    system = ActorSystem("multiprocQueueBase", logDefs=logcfg)
    main = system.createActor(FooBar)
    system.tell(main, Init())

Error

ERROR  ActorAddr-Q.ThespianQ.b => Actor __main__.Main @ ActorAddr-Q.ThespianQ.b retryable exception on message <definitions.Init object at 0x7f9c82283af0>
Traceback (most recent call last):

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 642, in configure
    self.configure_root(root)

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 802, in configure_root
    self.common_logger_config(root, config, incremental)

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 783, in common_logger_config
    logger.removeHandler(h)

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/system/logdirector.py", line 183, in removeHandler
    raise NotImplementedError('Cannot add logging handlers for Thespian Actors')

NotImplementedError: Cannot add logging handlers for Thespian Actors

Traceback (most recent call last):

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/system/actorManager.py", line 164, in _handleOneMessage
    actor_result = self.actorInst.receiveMessage(msg, envelope.sender)

  File "main.py", line 98, in receiveMessage
    self.init()

  File "main.py", line 60, in init
    a = elf.createActor(Test)

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/actors.py", line 637, in __init__
    systemBase = self._startupActorSys(

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/actors.py", line 662, in _startupActorSys
    systemBase = thespian.system \

  File "/usr/local/anaconda3/lib/python3.8/site-packages/thespian/system/simpleSystemBase.py", line 257, in __init__
    if logDefs is not False: dictConfig(logDefs or defaultLoggingConfig)

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 808, in dictConfig
    dictConfigClass(config).configure()

  File "/usr/local/anaconda3/lib/python3.8/logging/config.py", line 644, in configure
    raise ValueError('Unable to configure root '

ValueError: Unable to configure root logger

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日记撕了你也走了 2025-01-25 16:42:33

您的示例代码在某种程度上不完整(即,不是遇到错误的代码的完整表示):可能有一些日志记录调用未显示。您遇到的 NotImplementedError 是由于尝试调用 logging.addHandler()logging.removeHandler() 造成的,这些方法不支持Actor 本身,因为 Thespian 中的日志记录支持提供了特定的处理程序。 Thespian 中的日志记录应通过 ActorSystem() 调用的 logDefs 参数进行初始化(请参阅 https://thespianpy.com/doc/using.html#hH-ce55494c-dd7a-4258-a1e8-b090c3bbb1e6)。

Your sample code is incomplete in some manner (i.e. not a complete representation of the code encountering the error): there are probably some logging calls that are not shown. The NotImplementedError you are encountering is due to an attempt to call logging.addHandler() or logging.removeHandler(), which are not supported for Actors themselves because the logging support in Thespian provides specific handlers. The logging in Thespian should be initialized via the logDefs argument to the ActorSystem() call (see https://thespianpy.com/doc/using.html#hH-ce55494c-dd7a-4258-a1e8-b090c3bbb1e6).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文