Open WOLFIE-OG opened 3 years ago
It does take some time, unfortunately I'm not too familiar with async in Python. Are you able to use multiprocessing or something to let the bot create a new thread to perform the search and then do something with the results once they come in?
It does take some time, unfortunately I'm not too familiar with async in Python. Are you able to use multiprocessing or something to let the bot create a new thread to perform the search and then do something with the results once they come in?
I can make it into a async subprocess but am i able to run it as a command from the command line then pass the out put?
Seems that requests
doesn’t do async. An obvious way to turn blocking calls into nonblocking ones is to push them off into a separate worker thread, and feed it requests via a Queue
. When a request has completed, the thread can return its result to a caller which is await
ing a Future
by putting the result into the future via call_soon_threadsafe
.
I am including the search in my discord bot, and it seems to freeze the bot while it searches
if setting == 'url': url=query elif setting == 'search': yt = YoutubeSearch(query, max_results=1).to_json() yt_id = str(json.loads(yt)['videos'][0]['id']) url = 'https://www.youtube.com/watch?v='+yt_id