Wednesday, October 30, 2013

gEvent friendly REPL

I was surprised how little code this was.  The fileobject module added in gEvent 1.0 and the standard library code module make this trivial.

import sys
import code
from gevent import fileobject

_green_stdin = fileobject.FileObject(sys.stdin)
_green_stdout = fileobject.FileObject(sys.stdout)

def _green_raw_input(prompt):
    _green_stdout.write(prompt)
    return _green_stdin.readline()[:-1]

def run_console(local=None, prompt=">>>"):
    code.interact(prompt, _green_raw_input, local=local or {})

if __name__ == "__main__":
    run_console()

1 comment:

  1. Official horse bridle offers, progress code and markdown codes. Ensured and endeavored voucher codes and bound time codes.

    ReplyDelete