0

I'm trying to use threading in my program which checks username availability and claims available ones. The api which I check against has no rate limit, however, the one to which I claim available names has a rate limit of circa five requests.

I'm using threads on the checking function, and the checking function then directs to the creating function with self.claim(name) for available usernames. I just want to post a single request in the create/claim while the checking function checks at around 200rq/s

class main():

    # create account
    # do this just once
    def claim(self, user):
        r = requests.post(f'https://somewebsite.com/{user}')

    # check if available
    # run with threads
    def check(self):
        r = requests.get(f'https://somewebsite.com/{name}')
        if 'available' in r.text:
            self.claim(name) # create acc.

    # threads
    def threads(self):
        for i in range(150):
            threading.Thread(target=self.checker, args=()).start()
  • `name` is undefined in check... `self.checker` is undefined in threads. And you have no __init__. – kpie Nov 25 '21 at 21:12
  • @kpie Does it look like it's actual code? It's just an example of my code –  Nov 25 '21 at 21:13
  • 2
    It would be easier to know what your problem is if your example worked. – kpie Nov 25 '21 at 21:15
  • @kpie My actual code is over five hundred lines, so therefore this minimal example; which shows JUST the threading issue I'm dealing with. Which is the PROBLEM I'm facing –  Nov 25 '21 at 21:16
  • Are you going to `join` your threads back at some point? Look at this post for getting data back from threads, once you have those values you're off to the races claiming usernames right? (Because your problem is finding too many available usernames in a short time period right?) So check, join, then claim. https://stackoverflow.com/questions/6893968/how-to-get-the-return-value-from-a-thread-in-python – kpie Nov 25 '21 at 21:23
  • Maybe you could explain what it is that you want somebody to explain to you. The way your "question" is written, it looks as if you are hoping that somebody will write your code for you. You might get lucky, but usually, people here won't do that. – Solomon Slow Nov 25 '21 at 21:28

0 Answers0