def __init__(self, name=None, logfunc=None, user=None, **kwds): wx.App.__init__(self, redirect=False, **kwds) self.Bind(EVT_PIA_SERVICE, self.__service_ctx) self.Bind(EVT_PIA_ASYNC, self.__service_async) self.mgr = piagent.scaffold_gui(utils.notify(self.__service), utils.notify(self.__service_shutdown), utils.stringify(logfunc), utils.stringify(None), False, False) self.__env_bg = self.mgr.bgcontext('main', utils.statusify(None), utils.stringify(logfunc), name or 'App') self.__env_fg = self.mgr.context('main', utils.statusify(None), utils.stringify(logfunc), name or 'App') piw.setenv(self.__env_fg.getenv()) self.__stdio = (sys.stdout, sys.stderr) sys.stdout = session.Logger() sys.stderr = sys.stdout self.__thing = piw.thing() self.__thing.set_slow_trigger_handler(utils.notify(self.__trigger)) self.__queue = [] self.__lock = picross.mutex() self.run_bg_sync(self.__setup)
def run_session(session, user=None, mt=1, name='ctx', logger=None, clock=True, rt=True): def logfunc(msg): if logger: logger(msg) else: print context = None def ctxdun(status): context.release() scaffold = piagent.scaffold_mt(mt, utils.stringify(logfunc), utils.stringify(None), clock, rt) context = scaffold.context('main', utils.statusify(ctxdun), utils.stringify(logfunc), name) stdio = (sys.stdout, sys.stderr) x = None try: if logger: sys.stdout = Logger() sys.stderr = sys.stdout piw.setenv(context.getenv()) piw.tsd_lock() try: x = session(scaffold) context.trigger() finally: piw.tsd_unlock() scaffold.wait() finally: sys.stdout, sys.stderr = stdio return x
def setUp(self): self.context = self.manager.context(utils.notify(None), utils.stringify(self.logger), 'test') piw.setenv(self.context.getenv()) if self.logger is not None: self.oldstd = sys.stdout, sys.stderr sys.stdout, sys.stderr = self.logger.Logger(), sys.stdout
def make_logger(prefix, logfunc): def logger(msg): logfunc("%s: %s" % (prefix, msg)) return utils.stringify(logger)