Comments (6)
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.
Can you provide an example? I have tried using a similar method but it does not work.
from dingolingo.
If I didn't forget something, I just used this decorator and added await before search_youtube
from dingolingo.
Did we found a solution to this issue that we can apply?
from dingolingo.
If I didn't forget something, I just used this decorator and added await before search_youtube
?
from dingolingo.
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).
DingoLingo/musicbot/audiocontroller.py
Lines 237 to 245 in 6790bbb
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)
- TypeError: Client.start() got an unexpected keyword argument 'bot' HOT 2
- Update requirements HOT 1
- Songs with colons (:) in their names causes the Bot to stop working. HOT 3
- missing 1 required keyword-only argument: 'intents' HOT 3
- Not Working on Heroku HOT 3
- Change discord-py to py-cord. HOT 1
- Running bot as .pyw prevents music from playing HOT 2
- Bot doesn't respond to any command, and gives error. HOT 5
- Help HOT 2
- The bot doesn't play anything HOT 4
- Nothing gets added to queue HOT 3
- I can't use commands HOT 3
- I have a problem with intents HOT 3
- run.py is missing intents (.galex_ on discord)
- Cant play music: ClientException: ffmpeg was not found. HOT 1
- The bot responds to commands but does not play songs
- The above exception was the direct cause of the following exception: HOT 1
- Error: name 'Settings' is not defined
- Error when i opening run.py HOT 1
- The bot doesn't respond when I text it on the server. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dingolingo.