I am working on code that accesses an api that's not made using asyncio along with a discord bot that uses asyncio. In my dsicord commands I created local functions with the blocking parts of the api and want to run them with BaseEventLoop.run_in_executer
with a ProcessPoolExecutor
object.
Example:
@client.command()
def someCommand(...):
... processing where lots of local variables are defined
def task():
... blocking code making use of lots of local variables
loop.run_in_executer(processPool, task)
Some very useful answers are given around the multiprocessing module here. Are there any similar solutions without moving the functions to global space where a lot of unwanted clutter will be created :( ? Having the blocking functions defined locally makes the code more clean and readable. I already have hundreds of functions in my file and don't want to add unnecessary global space clutter.