prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.37k stars 716 forks source link

assert app._is_running #971

Open brusand opened 5 years ago

brusand commented 5 years ago

i try to use this sequence of code but when i i execute session.prompt at the second time i have this error : assert app._is_running

is there a better sequence of coding ? our_history = FileHistory('.example-history-file') session = PromptSession(history=our_history) batch = GBatch() args = batch.parser.parse_args() batch.init(args) print ("Welcome ", batch.player) args.func(args) guru = True

while True:
    with patch_stdout():
        cmd = session.prompt(" >> ")
    if cmd:
        args = batch.parser.parse_args(cmd.split())
        args.cmde = cmd
        args.func(args)
        if batch.bye:
            break

here the trace AssertionError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/bruno/gsprompt/venv/lib/python3.7/site-packages/prompt_toolkit/eventloop/base.py", line 129, in call_exception_handler self._exception_handler(context) File "/Users/bruno/gsprompt/venv/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 702, in handle_exception run_coroutine_in_terminal(print_exception) File "/Users/bruno/gsprompt/venv/lib/python3.7/site-packages/prompt_toolkit/application/run_in_terminal.py", line 62, in run_coroutine_in_terminal assert app._is_running AssertionError

jonathanslenders commented 5 years ago

I'm not sure what's going on, but a few things you can try: