Find answers from the community

Updated 4 weeks ago

Using a Pool to Run a Long-Running Function in the Background Without Blocking the Main Thread

Hi everyone! I have a chatbot with a tool (created using class CustomToolSpec(BaseToolSpec)), and want to start a background process thats take time, and send just a message to user... I already try something like:

Plain Text
        with multiprocessing.Pool(processes=1) as pool:
                future = pool.apply_async(self.my_long_function, args=(my_args,))
        return "Thanks, I will start the long-function."


but my_long_function are never called. Any way to accomplish this?
L
1 comment
if your function/code is async, I would just use asyncio.create_task instead of messing around with multiprocessing
Add a reply
Sign up and join the conversation on Discord