How to use _start_threads method in autotest

Best Python code snippet using autotest_python

threads.py

Source:threads.py Github

copy

Full Screen

...13 self.threads = Queue.Queue(0)14 self.function = function15 self.numthreads = 016 self.queue = Queue.Queue(0)17 self._start_threads(numthreads)18 def wait(self):19 """ Checks to see if any threads are still working and20 blocks until worker threads all complete. """21 for x in xrange(self.numthreads):22 self.queue.put('die')23 # As only spawned threads are allowed to add new ones,24 # we can safely wait for the thread queue to be empty25 # (if we're at the last thread and it creates a new one,26 # it will get queued before it finishes).27 dead = 028 while True:29 try:30 thread = self.threads.get(block=True, timeout=1)31 if thread.isAlive():32 thread.join()33 dead += 134 except Queue.Empty:35 assert(dead == self.numthreads)36 return37 def queue_work(self, data):38 """ Takes a list of items and appends them to the39 work queue. """40 [self.queue.put(item) for item in data]41 def add_one_thread_post_wait(self):42 # Only a spawned thread (not the main one)43 # should call this (see wait() for details)44 self._start_threads(1)45 self.queue.put('die')46 def _start_threads(self, nthreads):47 """ Start up threads to spawn workers. """48 self.numthreads += nthreads49 for i in xrange(nthreads):50 thread = threading.Thread(target=self._new_worker)51 thread.setDaemon(True)52 self.threads.put(thread)53 thread.start()54 def _new_worker(self):55 """ Spawned worker threads. These threads loop until queue is empty."""56 while True:57 # Blocking call58 data = self.queue.get()59 if data == 'die':60 return...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful