def main(argv=sys.argv): try: # If stdout is a pipe, re-open it line buffered if utils.isapipe(sys.stdout): # Hold a reference to the previous file object so it doesn't # get garbage collected and close the underlying descriptor. stdout = sys.stdout sys.stdout = os.fdopen(stdout.fileno(), 'w', 1) '''Main method called by the eggsecutable.''' config = os.environ.get('AGENT_CONFIG') agent = PlatformAgent(config_path=config) agent.run() except KeyboardInterrupt: pass
class StandAloneMatLab(Agent): '''The standalone version of the MatLab Agent''' @PubSub.subscribe('pubsub', _topics['volttron_to_matlab']) def print_message(self, peer, sender, bus, topic, headers, message): print('The Message is: ' + str(message)) message_out = script_runner(message) self.vip.pubsub.publish('pubsub', _topics['matlab_to_volttron'], message=message_out) if __name__ == '__main__': try: # If stdout is a pipe, re-open it line buffered if utils.isapipe(sys.stdout): # Hold a reference to the previous file object so it doesn't # get garbage collected and close the underlying descriptor. stdout = sys.stdout sys.stdout = os.fdopen(stdout.fileno(), 'w', 1) print(remote_url()) agent = StandAloneMatLab(address=remote_url(), identity='standalone_matlab') task = gevent.spawn(agent.core.run) try: task.join() finally: task.kill() except KeyboardInterrupt: pass
bar_result = self.vip.rpc.call(IDENTITY, 'bar').get(timeout=5) sys.stdout.write('bar returned: {}\n'.format(bar_result)) @RPC.export def foo(self): return 'Anybody can call this function via RPC' @RPC.export @RPC.allow('can_call_bar') def bar(self): return 'If you can see this, then you have the required capabilities' if __name__ == '__main__': try: # If stdout is a pipe, re-open it line buffered if utils.isapipe(sys.stdout): # Hold a reference to the previous file object so it doesn't # get garbage collected and close the underlying descriptor. stdout = sys.stdout sys.stdout = os.fdopen(stdout.fileno(), 'w', 1) print(remote_url()) agent = StandAloneWithAuth(address=remote_url(), identity=IDENTITY) task = gevent.spawn(agent.core.run) try: task.join() finally: task.kill()