-
Notifications
You must be signed in to change notification settings - Fork 128
-
Hi!
I'm new to asyncio in python, and need a bit of help how to add async things.
I'd like to have an async initialization method (for an autocomplete), but I don't want to block the user and let them use the app while querying. Not even starting is ever printed...
import asyncio import cmd2 class MyCmdApp(cmd2.Cmd): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.loop = asyncio.get_event_loop() self.result = 'not yet' self.task = self.loop.create_task(self.long_running_task()) print(self.task) async def long_running_task(self): # Simulate a long-running task self.poutput('Starting') await asyncio.sleep(5) self.result = "Done!" print("done") def do_pr(self, _): print(self.result) if __name__ == '__main__': app = MyCmdApp() app.cmdloop()
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment