0

Apologies if i've worded the question a bit wrong, but I'm working on a script which automates the checkout process of a certain e-commerce website. However, I would need to run a seperate thread to harvest google recaptchas and store them in a queue since they will need to be used when sending POST requests. Would it be possible to start only the harvesting thread when the program starts and then start the checkout process based on input (e.g. when the user hits enter or something)?

Also since google recaptcha tokens expire after a certain amount of time, is there a way that I can pop it off the queue without having to keep polling the queue?

Thanks in advance.

JC1
  • 849
  • 13
  • 25

1 Answers1

0

Would it be possible to start only the harvesting thread when the program starts and...

A thread starts when your code starts it. If you write code that starts a new thread when your program starts, then it will start a new thread when your program starts.

If you need to insure that other threads do not start until the first thread has completed some task, then that's a different story. You will need to use some synchronization object such as a countdown latch to make the main thread (or other threads) wait for the task to be completed.

Since google recaptcha tokens expire after a certain amount of time, is there a way that I can pop it off the queue without having to keep polling the queue?

I'd use a separate data structure for that: Probably a min heap to keep track of which object will be the next one to expire.

Community
  • 1
  • 1
Solomon Slow
  • 25,130
  • 5
  • 37
  • 57
  • Hm, a min heap sounds like a good idea. Forgot to add that the queue is a queue of dicts with a token and time of harvest value. How would I order the tokens based on time of harvest though, would I still have to use a dict? – JC1 May 08 '17 at 14:08