return True except Exception: traceback.print_exc(file=sys.stderr, limit=0) return False def verify(self): return self.fn is not None def run(self, args, env): # initialize the namespace for the execution namespace = {} result = None try: os.environ = env namespace['param'] = args exec(self.fn, namespace) exec('fun = %s(param)' % self.mainFn, namespace) result = namespace['fun'] except Exception: traceback.print_exc(file=sys.stderr) if result and isinstance(result, dict): return (200, result) else: return (502, {'error': 'The action did not return a dictionary.'}) if __name__ == '__main__': setRunner(PythonRunner()) main()
cwd=DEST_SCRIPT_DIR) # run the process and wait until it completes. # stdout/stderr will not be None because we passed PIPEs to Popen (o, e) = p.communicate() # stdout/stderr may be either text or bytes, depending on Python # version, so if bytes, decode to text. Note that in Python 2 # a string will match both types; so also skip decoding in that case if isinstance(o, bytes) and not isinstance(o, str): o = o.decode('utf-8') if isinstance(e, bytes) and not isinstance(e, str): e = e.decode('utf-8') if o: sys.stdout.write(o) sys.stdout.flush() if e: sys.stderr.write(e) sys.stderr.flush() def env(self, message): env = ActionRunner.env(self, message) return env if __name__ == '__main__': setRunner(Swift4Runner()) main()
try: self.fn = compile(message["code"], filename = 'action', mode = 'exec') except Exception: traceback.print_exc(file = sys.stderr, limit = 0) return self.verify() def verify(self): return self.fn is not None def run(self, args, env): # initialize the namespace for the execution namespace = {} result = None try: os.environ = env namespace['param'] = args exec(self.fn, namespace) exec("fun = %s(param)" % self.mainFn, namespace) result = namespace['fun'] except Exception: traceback.print_exc(file = sys.stderr) if result and isinstance(result, dict): return (200, result) else: return (502, { 'error': 'The action did not return a dictionary.'}) if __name__ == "__main__": setRunner(PythonRunner()) main()
# run the process and wait until it completes. # stdout/stderr will not be None because we passed PIPEs to Popen (o, e) = p.communicate() # stdout/stderr may be either text or bytes, depending on Python # version. In the latter case, decode to text. if isinstance(o, bytes): o = o.decode('utf-8') if isinstance(e, bytes): e = e.decode('utf-8') if o: sys.stdout.write(o) sys.stdout.flush() if e: sys.stderr.write(e) sys.stderr.flush() def env(self, message): env = ActionRunner.env(self, message) args = message.get('value', {}) if message else {} env['WHISK_INPUT'] = json.dumps(args) return env if __name__ == '__main__': setRunner(Swift3Runner()) main()
# run the process and wait until it completes. # stdout/stderr will not be None because we passed PIPEs to Popen (o, e) = p.communicate() # stdout/stderr may be either text or bytes, depending on Python # version, so if bytes, decode to text. Note that in Python 2 # a string will match both types; so also skip decoding in that case if isinstance(o, bytes) and not isinstance(o, str): o = o.decode('utf-8') if isinstance(e, bytes) and not isinstance(e, str): e = e.decode('utf-8') if o: sys.stdout.write(o) sys.stdout.flush() if e: sys.stderr.write(e) sys.stderr.flush() def env(self, message): env = ActionRunner.env(self, message) args = message.get('value', {}) if message else {} env['WHISK_INPUT'] = json.dumps(args) return env if __name__ == '__main__': setRunner(Swift3Runner()) main()
def __init__(self): ActionRunner.__init__(self) def init(self, message): if 'code' in message and message['code'] == 'sleep': # sleep forever/never respond while True: print("sleeping") time.sleep(60) elif 'code' in message and message['code'] == 'exit': print("exiting") sys.exit(1) else: return ActionRunner.init(self, message) def run(self, args, env): if 'sleep' in args: # sleep forever/never respond while True: print("sleeping") time.sleep(60) elif 'exit' in args: print("exiting") sys.exit(1) else: return ActionRunner.run(self, args, env) if __name__ == "__main__": setRunner(Runner()) main()