无法为thespian演员添加伐木处理程序
然而,尝试在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的示例代码在某种程度上不完整(即,不是遇到错误的代码的完整表示):可能有一些日志记录调用未显示。您遇到的
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 calllogging.addHandler()
orlogging.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 thelogDefs
argument to theActorSystem()
call (see https://thespianpy.com/doc/using.html#hH-ce55494c-dd7a-4258-a1e8-b090c3bbb1e6).