0
我下面在this thread例子來嘗試發佈消息發送到遠程VOLTTRON平臺,並在遠程平臺運行和設置正確它工作正常。 但是,當遠程平臺未運行時,發佈功能將永遠保持阻止狀態,並且不會超時。這可以防止檢測遠程平臺何時未運行,並防止執行其餘代碼。VIP發佈功能不超時當遠程平臺是死
from volttron.platform.vip.agent import Core, Agent
import gevent
def vip_publish(topic,message, address=None):
retry = 3
while retry>0:
pub_agent = Agent(address=address)
my_event = gevent.event.Event()
pub_agent.core.onstart.connect(lambda *a, **kw: my_event.set(),my_event)
agent_thread = gevent.spawn(pub_agent.core.run)
my_event.wait()
try:
#The following line remains blocking forever when remote volttron platform is not running
pub_agent.vip.pubsub.publish(peer='pubsub', topic=topic, message=message).get(timeout=1)
except gevent.Timeout:
print "Time-out"
retry -= 1
else:
retry = 0
agent_thread.kill()