def run(name,input, interpreter=Interpreter, logger=None): global ht if logger is None: ht = run_logger(name,dot=False) logger = ht.log if isinstance(input,unicode): input = input.encode("utf-8") input = StringIO(input) def _main(): global ht parse_ctx = Context(filename=name) #parse_ctx.logger=parse_logger try: parse(input, interpreter(Context(out=logwrite(logger))),parse_ctx) except Exception as e: fix_exception(e) print_exception(e,file=sys.stderr) finally: shut_down() if ht is not None: ht.try_exit() ht = None mainloop(_main) if ht is not None: ht.try_exit() sys.exit(exitcode)
## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License (included; see the file LICENSE) ## for more details. ## from homevent.database import DbStore from homevent.base import Name from homevent.reactor import shut_down,mainloop s = DbStore(Name("Foo","bar")) def main(): #d.addCallback(lambda _: s.set("one",2)) #d.addCallback(lambda _: s.set(3,(4,5,6))) def getter(a,b): _ = s.get(a) assert _ == b, "Check CallBack %r %r %r" % (_,a,b) getter("one",2) getter(("two","three"),(4,5,6)) s.delete(("two","three")) s.delete("one") shut_down() mainloop(main)
def looper(): while True: print "L" sleep(1) def ready(): c=Context() for f in sys.argv[1:]: read_config(c,f) parse(f, interpreter, ctx=c) #c.logger=parse_logger if os.isatty(0): i = InteractiveInterpreter else: i = Interpreter print """Ready. Type «help» if you don't know what to do.""" try: parse(sys.stdin, interpreter=i, ctx=c) except Exception as e: fix_exception(e) reporter(e) shut_down() from gevent import spawn,sleep #spawn(looper) callLater(False,0.1,ready) mainloop()
print >>pid, os.getpid() pid.close() def _readcf(): c = Context() try: for f in args: parse(f,ctx=c) except Exception as e: fix_exception(e) process_failure(e) shut_down() reading = None def readcf(): global reading if reading: return reading = gevent.spawn(_readcf) def read_done(_): global reading reading = False reading.link(read_done) signal(SIGINT, lambda a,b: gevent.spawn(shut_down)) signal(SIGQUIT,lambda a,b: gevent.spawn(shut_down)) signal(SIGHUP, lambda a,b: readcf()) mainloop(setup=readcf)