I have a function that compiles some text together using discord.py, then makes several calls to to openai using llamaindex to get some responses back. I then post the responses from openai back into a discord channel.
I keep getting Shard ID blocking errors due to thread blocking but I thought asynco tasks were run as separate threads. I don't have the knowledge to figure out what I'm doing wrong. I run post_morningbrief() as an asyncio task:
taskPostMorningBrief = asyncio.create_task(post_morningbrief(test_channelID))
Then this function takes anywhere from 5-30 seconds to complete due to the discord and openai calls. What I dont understand is how create_task is blocking the main thread when everything I read about asyncio makes it sound like it runs concurrently. It's been suggested that my question is a duplicate however I still don't understand why a separate thread would block the main thread if it is supposed to be running in the background. I'm not sure how to rephrase the question any better.
async def post_morningbrief(channel_ID):
c_channel = client.get_channel(channel_ID)
weatherresponse = await weather_report() # Make our weather report
events = await ingest_events() #pull scheduled events from discord
annouce = await ingest_announcements() #pull the latest announcements
briefresponse = await morning_brief(events, annouce) #make our brief including announcements, events
reformat_prompt = 'Rewrite this morning brief so the topics are in a different order. Elaborate or change things a little. Only greet us once in the beginning of the new brief: \n'+str(weatherresponse)+'\n'+str(briefresponse)
reformat_response = querybot.handle_chat_request(reformat_prompt)
await c_channel.send(reformat_response)