def get_kernel(): try: return _locals.curio_kernel except AttributeError: _locals.curio_kernel = k = curio.Kernel() if 'CURIOMONITOR' in os.environ: m = Monitor(k) k._call_at_shutdown(m.close) return k
def get_kernel(selector=None, with_monitor=False): """Return an curio.Kernel object with our selector. This is a singleton object. """ global _default_kernel if _default_kernel is None: _get_kernel(selector=selector) if with_monitor or 'CURIOMONITOR' in os.environ: from curio.monitor import Monitor m = Monitor(_default_kernel) _default_kernel._call_at_shutdown(m.close) return _default_kernel
def run( corofunc, *args, with_monitor=False, selector=None, debug=None, activations=None, toplevel=None, select_interval=None, **kernel_extra, ): """ Run the guio kernel with an initial task and execute until all tasks terminate. Returns the task's final result (if any). This is a convenience function that should primarily be used for launching the top-level task of a guio-based application. It creates an entirely new kernel, runs the given task to completion, and concludes by shutting down the kernel, releasing all resources used. Don't use this function if you're repeatedly launching a lot of new tasks to run in guio. Instead, create a Kernel instance and use its run() method instead. """ kernel = Kernel( selector=selector, debug=debug, activations=activations, toplevel=toplevel, select_interval=select_interval, **kernel_extra, ) # Check if a monitor has been requested if with_monitor or "CURIOMONITOR" in os.environ: from curio.monitor import Monitor m = Monitor(kernel) kernel._call_at_shutdown(m.close) kernel.run(m.start) with kernel: return kernel.run(corofunc, *args)
def kernel(request): k = Kernel(debug=[longblock, logcrash, schedtrace, traptrace]) m = Monitor(k) request.addfinalizer(lambda: k.run(shutdown=True)) request.addfinalizer(m.close) return k
def kernel(request): k = Kernel() m = Monitor(k) request.addfinalizer(lambda: k.run(shutdown=True)) request.addfinalizer(m.close) return k