import asyncio import os.path from concurrent.futures import ThreadPoolExecutor from arty.thread_queue import ThreadQueue from arty.worker import Worker from arty.make_image import make_image from arty.utils import get_token, run_in_thread from arty.bot import Bot def _init(): lock = os.path.join(os.path.dirname(__file__), '.first_init') if os.path.isfile(lock): return print('running first time setup. this will take some time.') make_image('something cute', num_images=1) with open(lock, 'w') as f: f.write('done') print('first time setup done.') async def _main(): worker_queue = ThreadQueue() bot_queue = ThreadQueue() worker = Worker(bot_queue, worker_queue) bot = Bot(get_token('discord'), bot_queue, worker_queue) executor = ThreadPoolExecutor(max_workers=2) loop = asyncio.get_event_loop() await asyncio.wait( fs={ loop.run_in_executor(executor, run_in_thread, worker), loop.run_in_executor(executor, run_in_thread, bot), }, return_when=asyncio.ALL_COMPLETED ) if __name__ == '__main__': _init() asyncio.run(_main())