'RuntimeWarning: coroutine 'function' was never awaited self._target(*self._args, **self._kwargs)

I'm using below code to run a async function using a thread, because if I run that in asyncio.run() it would freeze the GUI window.

However, it returns an error: RuntimeWarning: coroutine 'transcribe' was never awaited self._target(*self._args, **self._kwargs) RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Here is the code:


async def transcribe():
        # Initializes the Deepgram SDK
        dg_client = Deepgram(DEEPGRAM_API_KEY)

        global filename
        global PATH_TO_FILE
        PATH_TO_FILE = filename

        with open(filename, 'rb') as audio:
            source = {'buffer': audio, 'mimetype': MIMETYPE}
            options = {'punctuate': True, 'language': 'en-US'}

            print('Requesting transcript...')
            print('Your file may take up to a couple minutes to process.')
            print('While you wait, did you know that Deepgram accepts over 40 audio file formats? Even MP4s.')
            print('To learn more about customizing your transcripts check out developers.deepgram.com')

            response = await dg_client.transcription.prerecorded(source, options)
            print(response)
            print(response['results']['channels'][0]['alternatives'][0]['transcript'])

thread = threading.Thread(
    target =  transcribe 

)

button_10 = Button(
        image=button_image_1,
        borderwidth=0,
        highlightthickness=0,
        command=startProcessing,
        relief="flat"
    )

What should I do about this? Since the thread is not inside the async function, I can't use await either. I'm using Python 3.10. Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source