Best Python code snippet using avocado_python
thr-ex1.py
Source:thr-ex1.py
1#!/bin/env python2 # -*- coding: utf-8 -*-3 #filename: peartest.py4import threading, signal5is_exit = False6def doStress(i, cc):7 global is_exit8 idx = i9 while not is_exit:10 if (idx < 10000000):11 print "thread[%d]: idx=%d"%(i, idx)12 idx = idx + cc13 else:14 break15 if is_exit:16 print "receive a signal to exit, thread[%d] stop."%i17 else:18 print "thread[%d] complete."%i19def handler(signum, frame):20 global is_exit21 is_exit = True22 print "receive a signal %d, is_exit = %d"%(signum, is_exit)23if __name__ == "__main__":24 signal.signal(signal.SIGINT, handler)25 signal.signal(signal.SIGTERM, handler)26 cc = 527 threads = []28 for i in range(cc):29 t = threading.Thread(target=doStress, args=(i,cc))30 t.setDaemon(True)31 threads.append(t)32 t.start()33 while 1:34 alive = False35 for i in range(cc):36 alive = alive or threads[i].isAlive()37 if not alive:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!