Is there a way to stop a module that was started with runpy.run_module('module')?

I'm attempting to start a discord.py bot that is in a different py file and can successfully get the bot to start, however I'm not sure how to exit/stop the script once i've started it. ctrl+c works if I'm in in the shell however I have a pyqt script running the module and i'd like to keep the launcher up without closing it out as well.

@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


from Recent Questions - Stack Overflow https://ift.tt/3BbN0NF
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)