Closed tmokmss closed 2 years ago
It's interesting because it works in the main thread, but not in new threads. I do not know why this is. More than likely I misunderstood the use of get_event_loop
If we want to achieve the below behavior, how about this code?
the client pulls the current active loop or creates a new one.
try:
self.loop: AbstractEventLoop = asyncio.get_running_loop()
except RuntimeError:
# if there is no running loop, create a new event loop
self.loop: AbstractEventLoop = asyncio.new_event_loop()
I guess no event loop is set by default for a new thread.
Also note that starting from python 3.10, get_event_loop
becomes deprecated and it will be identical with get_running_loop
(doc)
If we want to achieve the below behavior, how about this code?
the client pulls the current active loop or creates a new one.
try: self.loop: AbstractEventLoop = asyncio.get_running_loop() except RuntimeError: # if there is no running loop, create a new event loop self.loop: AbstractEventLoop = asyncio.new_event_loop()
I guess no event loop is set by default for a new thread.
Also note that starting from python 3.10,
get_event_loop
becomes deprecated and it will be identical withget_running_loop
(doc)
Looks good. Do you want to make a pull request? If not, I will when I have a bit of free time next.
My job can betime consuming. Plus, 'twas your find :)
@isaackogan Hi thanks for the offer. I submitted a PR for this. Hope you can check it when you get a chance 🙏 .
Tested locally in 3.8, looks good. Merged into master and will be released in today's update
One comment, @tmokmss
If your intention is to run multiple clients, there's an IP rate limit for signing connections to respect fair use of TikTok services.
There are a million different reasons to thread, so I won't presume that's why you want to, but, just in-case you wanted to set up a bunch of clients at once, you will need an API key.
Thanks for the contribution, releasing the update now!
New API key feature? Sounds cool, thanks! I'm currently using it in my small hobby project (hoping it is not harming your server :pray: ) but I'll definitely contact you when I need larger-scale access.
For sure! The server can handle a few hundred requests a second before I'd need to up the capacity, which will never happen. Just don't want TikTok to tighten security again because the library is used for spam!
Thanks for the help, enjoy the new version! Isaac
Hi I'm a newbie who just started exploring TikTok world and thank you for developing this great toolkit! I found a weird behavior as below. Could you confirm it as expected or not? Thanks!
Describe the bug When I execute
TikTokLiveClient.run
on a newly created thread, it crashes.To Reproduce Run the code below:
and we get this error:
If I uncomment the two lines, it works without problem.
Shouldn't this be handled inside the library? I saw the following description in
README.md
Expected behavior Code runs without problem.
Additional context Add any other context about the problem here.