1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
      python3爬蟲(chóng)使用多線程運(yùn)算是不是會(huì)比較快-創(chuàng)新互聯(lián)

      這篇文章主要介紹了python3爬蟲(chóng)使用多線程運(yùn)算是不是會(huì)比較快,具有一定借鑒價(jià)值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。

      10余年專(zhuān)注成都網(wǎng)站制作,企業(yè)網(wǎng)站制作,個(gè)人網(wǎng)站制作服務(wù),為大家分享網(wǎng)站制作知識(shí)、方案,網(wǎng)站設(shè)計(jì)流程、步驟,成功服務(wù)上千家企業(yè)。為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù),專(zhuān)注于企業(yè)網(wǎng)站制作,高端網(wǎng)頁(yè)制作,對(duì)電動(dòng)窗簾等多個(gè)行業(yè),擁有多年的網(wǎng)站營(yíng)銷(xiāo)經(jīng)驗(yàn)。

      多線程存在GIL(global interpret lock)。為了實(shí)現(xiàn)多線程功能,程序把線程鎖住,然后鎖住了之后,只有一個(gè)線程運(yùn)算。Python只能夠讓線程在同一時(shí)間運(yùn)算一個(gè)東西。在不停切換,看起來(lái)是多線程的。但實(shí)際上不是。

      import threading
      from queue import Queue
      import copy
      import time
       
      def job(lists, q):
          res = sum(lists)
          q.put(res)
          
      def multi_theading(lists):
          q = Queue()
          threads = []
          for i in range(4):
              t = threading.Thread(target=job, args=(copy.copy(lists), q),
                                   name = 'T%i'%i)
              t.start()
              threads.append(t)
          [t.join() for i in threads]
          total = 0
          for _ in range(4):
              total += q.get()
          print(total)
       
      def normal(lists):
          # 完全不用多線程
          total = sum(lists)
          print(total)
       
      if __name__ == '__main__':
          lists = list(range(1000000))
          s_t = time.time()
          normal(lists*4)
          print('Normal : ', time.time() - s_t)
          s_t = time.time()
          multi_theading(lists)
      print('multi_threading : ', time.time() - s_t)


      運(yùn)行結(jié)果

      1999998000000
      Normal :  0.1705458164215088
      1999998000000
      multi_threading :  0.14860320091247559

      不用多線程是 0.1705秒;用了多線程僅僅是稍微快了一點(diǎn)。

      感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享python3爬蟲(chóng)使用多線程運(yùn)算是不是會(huì)比較快內(nèi)容對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,遇到問(wèn)題就找創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,詳細(xì)的解決方法等著你來(lái)學(xué)習(xí)!


      分享文章:python3爬蟲(chóng)使用多線程運(yùn)算是不是會(huì)比較快-創(chuàng)新互聯(lián)
      標(biāo)題鏈接:http://ef60e0e.cn/article/dgjsed.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        青浦区| 双鸭山市| 太湖县| 福清市| 凌海市| 蓝田县| 怀远县| 瓮安县| 上犹县| 白河县| 娱乐| 拜泉县| 周至县| 玉屏| 双辽市| 祁东县| 和硕县| 义马市| 揭东县| 武威市| 彭阳县| 格尔木市| 海晏县| 迭部县| 当阳市| 泾源县| 汝州市| 微博| 梁河县| 贵阳市| 金湖县| 水城县| 德令哈市| 灵璧县| 开江县| 馆陶县| 霞浦县| 惠来县| 昌乐县| 永城市| 来安县|