我正在尝试启动一个位于不同 py 文件中的 discord.py 机器人,并且可以成功地启动该机器人,但是我不知道一旦我启动它后如何退出/停止脚本。如果我在 shell 中,ctrl+c 可以工作,但是我有一个运行模块的 pyqt 脚本,我想在不关闭它的情况下保持启动器。
@click.group(invoke_without_command=True, options_metavar='[options]')
@click.pass_context
@click.option('-c', '--cli', help='launch hangoutcore without a gui.', is_flag=True)
def main(ctx, cli):
"""Launches the bot."""
if ctx.invoked_subcommand is None:
# since cli is a bool we can pass it as an environment variable so it can be accessed by any code running in this session.
os.environ["bot_CLI"] = str(cli)
print(os.environ["bot_CLI"])
if not cli:
try:
qasync.run(botLauncher())
except asyncio.exceptions.CancelledError as e:
print(e)
else:
try:
hangoutcore = runpy.run_module('hangoutcore')
print(hangoutcore)
except SystemExit as exception:
exitcode = exception.code
else:
exitcode = 0