Giter VIP home page Giter VIP logo

Comments (6)

lk2322 avatar lk2322 commented on July 17, 2024

We can use decorator like this

from functools import wraps, partial
import asyncio

def run_async(func):
    @wraps(func)
    async def run(*args, loop=None, executor=None, **kwargs):
        if loop is None:
            loop = asyncio.get_event_loop()
        pfunc = partial(func, *args, **kwargs)
        return await loop.run_in_executor(executor, pfunc)

    return run

from dingolingo.

Raptor123471 avatar Raptor123471 commented on July 17, 2024

Can you provide an example? I have tried using a similar method but it does not work.

from dingolingo.

lk2322 avatar lk2322 commented on July 17, 2024

If I didn't forget something, I just used this decorator and added await before search_youtube

from dingolingo.

malikmajai avatar malikmajai commented on July 17, 2024

Did we found a solution to this issue that we can apply?

from dingolingo.

malikmajai avatar malikmajai commented on July 17, 2024

If I didn't forget something, I just used this decorator and added await before search_youtube

?

from dingolingo.

RafaelSolVargas avatar RafaelSolVargas commented on July 17, 2024

If I didn't forget something, I just used this decorator and added await before search_youtube

Well, i tried to do that, the main problem in that it's not that simple. To be more specific, the preload function that uses asyncio to run multiple tasks at once doesn't support running coroutine or awaitable functions, and as you can see, the search_youtube funct is within the func down, forcing the def down to be a coroutine (so that he can use await search_youtube).

async def preload(self, song):
if song.info.title != None:
return
def down(song):
if song.host == linkutils.Sites.Spotify:
song.info.webpage_url = self.search_youtube(song.info.title)

This information was collected in this stackoverflow: https://stackoverflow.com/questions/46074841/why-coroutines-cannot-be-used-with-run-in-executor
I tried creating two search_youtube functions, one sync and one async, but other bugs were showing up and crashing the bot, so I gave up.

The solution to execute multiple coroutine functions at once is also in the stackoverflow, it's the second answer, but it's not simple and will require some major changes in the logic that interact with YoutubeDL.

https://github.com/RafaelSolVargas/Vulkan/blob/2dbc6c3984b2024ee14502b8b8cd8fd06c967f75/Music/Downloader.py#L108-L124
This is how another discord music bot deal with that exactly problem, the key here is to have an organized way to work with YoutubeDL, possibly using a class

from dingolingo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.