aioconsole icon indicating copy to clipboard operation
aioconsole copied to clipboard

[Question] Usage in non-console async scripts? aexec globals?

Open Serpens66 opened this issue 2 years ago • 0 comments

Hi,

I would like to use input/ainput for debugging purpose. So I start my python script in the console. And to use input I currently start a thread which simply does input() in a while True loop and "exec()" the input I enter. Then I can enter into the console something like "print(self.myvariable)" or other debbuging stuff.

Since I also use an asyncio loop in my script, I thought it might be more efficient to use an async input, instead of creating a thread for it. So I searched for it and found this aioconsole library. It seems to work to use ainput and aexec instead, but locals and globals are not accessable in aexec. I can do local=locals() for aexec, but how to also hand over globals() ?

Is aioconsole even the right module for this usecase?

Example code with none async that runs in a thread:

while True:
    put_in = input("\n") 
    try:
        exec(put_in)
    except Exception as err:
        print(err)

I can print any local or global variable from the script this way for debugging, or even set a variable to a new value.

Serpens66 avatar Oct 16 '22 17:10 Serpens66