python多进程(multiprocessing调用类函数)
Posted carlvine
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python多进程(multiprocessing调用类函数)相关的知识,希望对你有一定的参考价值。
#coding=utf-8 import os import multiprocessing from time import ctime, sleep from selenium import webdriver class testClass(object): def worker(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__": for i in range(2): a = testClass() p = multiprocessing.Process(target=a.worker, args=(2, "Chrome")) p.start() sleep(2) print("The number of CPU is:" + str(multiprocessing.cpu_count())) for p in multiprocessing.active_children(): print("child p.name:" + p.name + " p.id" + str(p.pid)) print("END!!!!!!!!!!!!!!!!!")
以上是关于python多进程(multiprocessing调用类函数)的主要内容,如果未能解决你的问题,请参考以下文章
python多进程-----multiprocessing包