Multithreading
#9749
Replies: 1 comment 2 replies
-
hi sorry for the late response~ async def send_results():
msg = await message.channel.send(f"{message.author.mention} Here are your results: ",file= discord.File(fp=image_bytesio, filename="image.jpeg"), embeds=sendEmbed, view = discord.ui.View().add_item(discord.ui.Button(label="Join My Discord Server", emoji=emoji,style=discord.ButtonStyle.gray, url="https://discord.gg/server")))
return msg
asyncio.run_coroutine_threadsafe(send_results(), client.loop) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I've been trying to make this discord bot that uses yolov8 object detection model for inference. I'm running the inference function inside the
on_message
event, but due to it's blocking nature, I can't make more than one request at a time. I was able to make multiple threads for the model instance, and was able to deal with multiple requests in parallel. Now the issue I'm facing is withmessage.channel.send
as it is a coroutine, but threads are only able to run synchronous functions. I was able to solve the messaging as well by usingasyncio.run_coroutine_threadsafe()
but only when I excludediscord.ui.View()
.code:
error:
It works fine, when I don't add it. I checked the source code, and I think it's not being able to detect the loop. Is there a way, I can pass the running loop to it?
Beta Was this translation helpful? Give feedback.
All reactions