avilash / TikTokAPI-Python

TikTok API Python Wrapper
http://avilashkumar.com/TikTokAPI-Python/
MIT License
443 stars 114 forks source link

If not running in main thread, create & set a new event loop. #7

Open ingo-m opened 4 years ago

ingo-m commented 4 years ago

When running TikTokAPI-Python in a subthread, I encountered an error:

RuntimeError: There is no current event loop in thread 'ThreadPoolExecutor-0_0'.

This RuntimeError does not occur when I use TikTokAPI-Python directly in a script (i.e. in the main python thread), but it does occur when calling TikTokAPI-Python from another (multithreaded) application. As far as I can see, if not running in the main thread, it's necessary to create & set a new event loop.

My proposed solution should not alter anything if running in the main thread, but avoid trouble otherwise.

balmacefa commented 2 years ago

You can also use https://github.com/erdewit/nest_asyncio

import nest_asyncio
nest_asyncio.apply()