aioconsole
aioconsole copied to clipboard
[Question] Usage in non-console async scripts? aexec globals?
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.