python多进程(multiprocessing调用类函数)

2018/07/03 15:36
阅读数 500
#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 + "\tp.id" + str(p.pid))
    print("END!!!!!!!!!!!!!!!!!")

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部