Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Serpens66 opened this issue Oct 16, 2022 · 0 comments
Open

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

Serpens66 opened this issue Oct 16, 2022 · 0 comments

Comments

@Serpens66
Copy link

Serpens66 commented Oct 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant