• 自己在项目中用到的多线程,同时控制线程数,仅供参考
    class scaner(threading.Thread):
     tlist = [] # list of all current scanner threads
     maxthreads = 100 # max number of threads we’re allowing
     evnt = threading.Event() # event to signal OK to create more threads
     lck = threading.Lock() # lock to guard tlist

     def init(self, host):
      threading.Thread.init(self)
      self.host = host # checking ports on this host

     def run(self):
      #######################
      ### do your method
      #######################
      scaner.lck.acquire()
      scaner.tlist.remove(self)
      if len(scaner.tlist) == scaner.maxthreads - 1:
       scaner.evnt.set()
       scaner.evnt.clear()
      scaner.lck.release()

     def newthread(host):
      scaner.lck.acquire()
      sc = scaner(host)
      scaner.tlist.append(sc)
      scaner.lck.release()
      sc.start()

     newthread = staticmethod(newthread)

    调用
    for host in hosts:

     scaner.lck.acquire()
     if len(scaner.tlist) >= scaner.maxthreads:
       # too bad, need to wait until not at thread limit
      scaner.lck.release()
      scaner.evnt.wait()
     else:
      scaner.lck.release()
     scaner.newthread(host)

  • @quqing,开始设置遍历深度3出现退回桌面情况,加大遍历深度后遍历效果有所改善,目前还没出现过返回桌面情况。建议加个包名判断,如果包名变化,新界面的节点不入任务栈并返回。

  • @quqing 经调试,是默认的窗口鉴定策略没配置好,没有使用identify-special, 使用identify-default,原配置对比的值8太小,很多页面前8个元素都相同导致窗口id返回值相同,最后索性传了整个driver.getPageSource()进去md5加密得以解决。遇到新的问是遍历过程中出现退回到桌面的情况。

  • @jennyyung 刚试用了下你的配置遍历知乎,出现了个问题是页面跳转后,当前节点任务所属窗口还是当前窗口,窗口没更新导致无法运行下去。

  • 好赞

  • 即做测试又做开发不可以吗?

  • 666666

  • 祝福找到好工作。

  • 不错不错

  • 计算机开放电子书汇总 at April 11, 2016

    谢谢楼主,收藏起来。