#Coding=utf-8ImportOSImportMultiprocessing fromTimeImportCTime, Sleep fromSeleniumImportWebdriverclassTestClass (object):defWorker (self, interval, browser="Chrome", url="Http://loginurl"): Driver= eval ("webdriver.%s ()"%browser) driver.get (URL) driver.find_element_by_id ("txtUserName"). Send_keys ("username") driver.find_element_by_id ("txtpwd"). Send_keys ("Password") Sleep (1) driver.find_element_by_id ("Btnlogin"). Click ()Print("I was at the %s%s"%(Browser, CTime ())) sleep (interval)Print("End Worker_2")if __name__=="__main__": forIinchRange (2): A=TestClass () p= multiprocessing. Process (Target=a.worker, args= (2,"Chrome") ) P.start () Sleep (2) Print("The number of the CPU is:"+Str (Multiprocessing.cpu_count ())) forPinchMultiprocessing.active_children ():Print("Child P.name:"+ P.name +"\tp.id"+str (p.pid))Print("END!!!!!!!!!!!!!!!!!")
Python multi-process (multiprocessing call class function)