首页 > 解决方案 > Volttron 进入了一个几乎无止境的循环

问题描述

我已经安装了大约 40 个代理来运行一些模拟。但是我遇到了一些线程错误。错误如下所示。

2019-08-06 10:56:24,120(socialagent-3.0 16231)错误:线程 Thread-31 中的异常:2019-08-06 10:56:24,124(socialagent-3.0 16231)错误:回溯(最近一次通话最后) :2019-08-06 10:56:24,135(socialagent-3.0 16231)错误:文件“/usr/lib/python2.7/threading.py”,第 801 行,在 __bootstrap_inner

2019-08-06 10:56:24,162(socialagent-3.0 16231)错误:
self.run()

2019-08-06 10:56:24,177(socialagent-3.0 16231)错误:文件“/usr/lib/python2.7/threading.py”,第 1073 行,正在运行

2019-08-06 10:56:24,198(socialagent-3.0 16231)错误:
self.function(*self.args,**self.kwargs)

2019-08-06 10:56:24,201(socialagent-3.0 16231)错误:文件“/home/jenny/.volttron/agents/50b42ee5-b6af-4a25-aa89-97e2b1a823e1/socialagent-3.0/social/agent.py” ,第 145 行,在 enter_phase3 中

2019-08-06 10:56:24,240 (socialagent-3.0 16231) 错误:
self.vip.pubsub.publish('pubsub', ids_topic, message=message)

2019-08-06 10:56:24,265(socialagent-3.0 16231)错误:文件“/home/jenny/workspace/volttron/volttron/platform/vip/agent/subsystems/pubsub.py”,第 607 行,在发布中

2019-08-06 10:56:24,267 (socialagent-3.0 16231) 错误:
self.vip_socket.send_vip(b'', 'pubsub', frames, result.ident, copy=False)

2019-08-06 10:56:24,279(socialagent-3.0 16231)错误:文件“/home/jenny/workspace/volttron/volttron/platform/vip/socket.py”,第 404 行,在 send_vip

2019-08-06 10:56:24,326 (socialagent-3.0 16231) 错误:
以 self._sending(flags) 作为标志:

2019-08-06 10:56:24,327(socialagent-3.0 16231)错误:文件“/usr/lib/python2.7/contextlib.py”,第 17 行,在 __enter__

2019-08-06 10:56:24,377(socialagent-3.0 16231)错误:
返回 self.gen.next()

2019-08-06 10:56:24,402(socialagent-3.0 16231)错误:文件“/home/jenny/workspace/volttron/volttron/platform/vip/green.py”,第 78 行,在 _sending

2019-08-06 10:56:24,413(socialagent-3.0 16231)错误:
虽然不是 lock.acquire(不是标志和 NOBLOCK):

2019-08-06 10:56:24,422(socialagent-3.0 16231)错误:文件“/home/jenny/workspace/volttron/env/local/lib/python2.7/site-packages/gevent/lock.py”,第 210 行,在获取中

2019-08-06 10:56:24,427(socialagent-3.0 16231)错误:rc = self._block.acquire(阻塞)

2019-08-06 10:56:24,442 (socialagent-3.0 16231) 错误:文件“gevent/_semaphore.py”,第 198 行,在 gevent._semaphore.Semaphore.acquire (gevent/gevent._semaphore.c:4117)

2019-08-06 10:56:24,451(socialagent-3.0 16231)错误:
def 获取(自我,阻塞=真,超时=无):

2019-08-06 10:56:24,485 (socialagent-3.0 16231) 错误:文件“gevent/_semaphore.py”,第 226 行,在 gevent._semaphore.Semaphore.acquire (gevent/gevent._semaphore.c:3944)

2019-08-06 10:56:24,493 (socialagent-3.0 16231) 错误:
timeout = self._do_wait(timeout)

2019-08-06 10:56:24,503 (socialagent-3.0 16231) 错误:文件“gevent/_semaphore.py”,第 166 行,在 gevent._semaphore.Semaphore._do_wait (gevent/gevent._semaphore.c:3178)

2019-08-06 10:56:24,546(socialagent-3.0 16231)错误:
结果 = get_hub().switch()

2019-08-06 10:56:24,552(socialagent-3.0 16231)错误:文件“/home/jenny/workspace/volttron/env/local/lib/python2.7/site-packages/gevent/hub.py”,第 609 行,在开关中

2019-08-06 10:56:24,574(socialagent-3.0 16231)错误:
返回 greenlet.switch(self)

2019-08-06 10:56:24,589(socialagent-3.0 16231)错误:LoopExit:('此操作将永远阻塞',)

2019-08-06 10:56:24,640(socialagent-3.0 16231)错误:

这正是我在 agent.py 文件中第 145 行的内容: self.vip.pubsub.publish('pubsub', ds_topic, message=message) 我已经将消息定义为 message = “something”</p>

当我安装较少的代理时,我根本不会遇到这个问题。我正在运行一台 1.9GHz Intel core i3 机器;这有关系吗?为了提供尽可能多的信息以帮助诊断问题,我在这里展示了我的代理的一些片段:

from threading import Timer

@Core.receiver("onstart")
def starting(self, sender, **kwargs):
    _log.debug('Subscribing to all relevant topics')
    self.vip.pubsub.subscribe('pubsub', pred_topic, callback=self.from_pred)  


def from_pred(self, peer, sender, bus, topic, headers, message):          
    message_dict = message_parser.mess_conv(message)
    message = "{}: {}".format(statID, message_dict['feat_pro'])
    # Publish to all neighbour topics and to our own topic
    for k in neighbours:
        self.vip.pubsub.publish('pubsub', k, message=message)
    self.vip.pubsub.publish('pubsub', social_topic, message=message)
    # ...and start timer to allow communication for 8s
    timer = Timer(8, self.enter_phase)
    timer.start()

def enter_phase(self):
    # Send a message to IDS to begin phase 
    _log.debug("In agent {}. We have {}".format(stationID, sent_prob))
    if stationID in sent_prob.keys():
        message = "phase3: 1"
    else:
        message = "phase3: 0"
    self.vip.pubsub.publish('pubsub', ds_topic, message=message)

另外,可能timer = Timer(8, self.enter_phase)是问题的一部分吗?我不是这样的开发大师,我会感谢任何帮助(用简单的语言:))。

标签: volttron

解决方案


这可能是由于猴子补丁问题而发生的。VOLTTRON 平台代码使用 gevent 修补套接字和未修补的线程。

您的代理是执行 monkey.patchall() 还是导入执行 gevent monkey.patchall() 的模块?您的代理是否依赖于需要未打补丁的 Socket 的包/其他库?如果您的代理需要未修补的 Socket 模块,您可以在代码中的 import Socket 语句之后执行 reload(socket) 。VOLTTRON 为 mongo historian 执行此操作(请参阅 volttron/platform/dbutils/mongoutils.py),因为 pymongo 库需要 unpatch 套接字和线程模块。


推荐阅读