如何使用asyncio运行python3后台进程

时间:2019-07-19 07:59:14

标签: python-3.x background-process python-asyncio

我需要使用asyncio库运行python3脚本,该脚本将阻止进程等待用户从命令行输入登录。在用户输入登录名后,python进程可以在后台进程中运行。

loop = asyncio.get_event_loop()
async def async_input(prompt):
    """
    Python's ``input()`` is blocking, which means the event loop we set
    above can't be running while we're blocking there. This method will
    let the loop run while we wait for input.
    """
    print(prompt, end='', flush=True)
    return (await loop.run_in_executor(None, sys.stdin.readline)).rstrip()

如果不循环运行.run_until_complete(self.is_user_authorized()):

   print('First run. Sending code request...')
   user_phone = input('Enter your phone: ')
   loop.run_until_complete(self.sign_in(user_phone))

我该怎么做?

0 个答案:

没有答案