然而,我试图在程序(Actor-Model system)中设置并行化,但我得到了一个错误,关于如何解决这个问题有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发布于 2022-04-05 04:50:50
您的示例代码在某种程度上是不完整的(即没有完整地表示遇到错误的代码):可能有一些日志调用没有显示。您遇到的NotImplementedError是由于试图调用logging.addHandler()或logging.removeHandler(),而Actors本身不支持它们,因为脚本中的日志记录支持提供了特定的处理程序。应该通过logDefs参数来初始化ActorSystem()调用中的日志记录(参见https://thespianpy.com/doc/using.html#hH-ce55494c-dd7a-4258-a1e8-b090c3bbb1e6)。
https://stackoverflow.com/questions/71732223
复制相似问题