#!/usr/bin/env python from ernie import mod, start from ernie import Ernie from time import sleep def calc_add(a, b): return a + b def slowcalc_add(a,b): sleep(2) return a + b def slowcalc_superslow(): sleep(10) def errorcalc_add(a,b): raise Exception("oops!") mod('calc').fun('add', calc_add) mod('slowcalc').fun('add', slowcalc_add) mod('slowcalc').fun('superslow', slowcalc_superslow) mod('errorcalc').fun('add', errorcalc_add) if __name__ == "__main__": start()
from ernie import mod, start from ernie import Ernie from time import sleep def calc_add(a, b): return a + b def slowcalc_add(a, b): sleep(2) return a + b def slowcalc_superslow(): sleep(10) def errorcalc_add(a, b): raise Exception("oops!") mod('calc').fun('add', calc_add) mod('slowcalc').fun('add', slowcalc_add) mod('slowcalc').fun('superslow', slowcalc_superslow) mod('errorcalc').fun('add', errorcalc_add) if __name__ == "__main__": start()
def iter_fib(n): a, b = 0, 1 for i in range(n): a, b = b, a + b # Normally this will "return a" but apparently there's an erlastic bug # that fails deserialization on bigints. Just return 1 and call it a day, # this is for testing only. return 1 def io_task(n=0): try: fd = TemporaryFile() while n != 0: fd.write("JUNKJUNKJUNKJUNKJUNKJUNK") n -= 1 fd.close() except IOError: pass except OSError: pass return 1 mod('fibmodule').fun('iter_fib', iter_fib) mod('fibmodule').fun('io_task', io_task) if __name__ == "__main__": start(daemon=False, async=True, forking=True)
from time import sleep def calc_add(a, b): return a + b def slowcalc_add(a, b): sleep(2) return a + b def slowcalc_superslow(): sleep(10) def errorcalc_add(a, b): raise Exception("oops!") mod('calc').fun('add', calc_add) mod('slowcalc').fun('add', slowcalc_add) mod('slowcalc').fun('superslow', slowcalc_superslow) mod('errorcalc').fun('add', errorcalc_add) if __name__ == "__main__": start(daemon=True) while True: sleep(100)
def iter_fib(n): a, b = 0, 1 for i in range(n): a, b = b, a + b # Normally this will "return a" but apparently there's an erlastic bug # that fails deserialization on bigints. Just return 1 and call it a day, # this is for testing only. return 1 def io_task(n=0): try: fd = TemporaryFile() while n != 0: fd.write("JUNKJUNKJUNKJUNKJUNKJUNK") n -= 1 fd.close() except IOError: pass except OSError: pass return 1 mod('fibmodule').fun('iter_fib', iter_fib) mod('fibmodule').fun('io_task', io_task) if __name__ == "__main__": start(daemon=False)