launch.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:Discord-ASM-Bot 作者: Emzi0767 项目源码 文件源码
def main():
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    asmbot.log("ASM version {} booting".format(asmbot.__version__), tag="ASM LDR")

    asmbot.log("Loading config", tag="PAM LDR")
    with open("config.json", "r") as f:
        cts = f.read()
        tkd = json.loads(cts)

    asmbot.log("Launching ASM", tag="ASM LDR")

    mp.set_start_method("spawn")
    executor = ThreadPoolExecutor(max_workers=int(tkd["shard_count"]))
    processes = []

    for i in range(0, int(tkd["shard_count"])):
        args = {
            "token": tkd["token"],
            "shard_id": i,
            "shard_count": int(tkd["shard_count"]),
            "script": tkd["script"],
            "guild_blacklist": tkd["guild_blacklist"],
            "guild_exempt_list": tkd["guild_exempt_list"]
        }

        loop.create_task(launch_process(executor, asmbotlauncher.initialize_asmbot, **args))

        if i != int(tkd["shard_count"]) - 1:
            loop.run_until_complete(asyncio.sleep(10))

    asmbot.log("Running", tag="ASM LDR")

    try:
        loop.run_until_complete(asyncio.gather(*asyncio.Task.all_tasks(loop)))

    except KeyboardInterrupt:
        pass

    finally:
        asmbot.log("Shutting down", tag="ASM LDR")
        for process in processes:
            process.join()

    asmbot.log("Shutdown finalized", tag="ASM LDR")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号