久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <bdo id='aZZ1I'></bdo><ul id='aZZ1I'></ul>

    <small id='aZZ1I'></small><noframes id='aZZ1I'>

    <i id='aZZ1I'><tr id='aZZ1I'><dt id='aZZ1I'><q id='aZZ1I'><span id='aZZ1I'><b id='aZZ1I'><form id='aZZ1I'><ins id='aZZ1I'></ins><ul id='aZZ1I'></ul><sub id='aZZ1I'></sub></form><legend id='aZZ1I'></legend><bdo id='aZZ1I'><pre id='aZZ1I'><center id='aZZ1I'></center></pre></bdo></b><th id='aZZ1I'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aZZ1I'><tfoot id='aZZ1I'></tfoot><dl id='aZZ1I'><fieldset id='aZZ1I'></fieldset></dl></div>
    <legend id='aZZ1I'><style id='aZZ1I'><dir id='aZZ1I'><q id='aZZ1I'></q></dir></style></legend>

        <tfoot id='aZZ1I'></tfoot>

      1. 如何在 django 視圖中使用 python 多處理模塊

        How to use python multiprocessing module in django view(如何在 django 視圖中使用 python 多處理模塊)
        <legend id='VrAWn'><style id='VrAWn'><dir id='VrAWn'><q id='VrAWn'></q></dir></style></legend>
          <tbody id='VrAWn'></tbody>

      2. <small id='VrAWn'></small><noframes id='VrAWn'>

          <bdo id='VrAWn'></bdo><ul id='VrAWn'></ul>
          • <i id='VrAWn'><tr id='VrAWn'><dt id='VrAWn'><q id='VrAWn'><span id='VrAWn'><b id='VrAWn'><form id='VrAWn'><ins id='VrAWn'></ins><ul id='VrAWn'></ul><sub id='VrAWn'></sub></form><legend id='VrAWn'></legend><bdo id='VrAWn'><pre id='VrAWn'><center id='VrAWn'></center></pre></bdo></b><th id='VrAWn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VrAWn'><tfoot id='VrAWn'></tfoot><dl id='VrAWn'><fieldset id='VrAWn'></fieldset></dl></div>

                <tfoot id='VrAWn'></tfoot>
                • 本文介紹了如何在 django 視圖中使用 python 多處理模塊的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我有一個(gè)簡(jiǎn)單的函數(shù)來(lái)遍歷 URL 列表,使用 GET 來(lái)檢索一些信息并相應(yīng)地更新 DB (PostgresSQL).該功能完美運(yùn)行.但是,一次一個(gè)地瀏覽每個(gè) URL 會(huì)占用太多時(shí)間.

                  I have a simple function that go over a list of URLs, using GET to retrieve some information and update the DB (PostgresSQL) accordingly. The function works perfect. However, going over each URL one at a time talking too much time.

                  使用 python,我可以執(zhí)行以下操作來(lái)并行執(zhí)行這些任務(wù):

                  Using python, I'm able to do to following to parallel these tasks:

                  from multiprocessing import Pool
                  
                  def updateDB(ip):
                       code goes here...
                  
                  if __name__ == '__main__':
                      pool = Pool(processes=4)              # process per core
                      pool.map(updateDB, ip)
                  

                  這工作得很好.但是,我試圖找到如何在 django 項(xiàng)目上做同樣的事情.目前我有一個(gè)函數(shù)(視圖),可以遍歷每個(gè) URL 以獲取信息并更新數(shù)據(jù)庫(kù).

                  This is working pretty well. However, I'm trying to find how do the same on django project. Currently I have a function (view) that go over each URL to get the information, and update the DB.

                  我唯一能找到的就是使用 Celery,但這對(duì)于我想要執(zhí)行的簡(jiǎn)單任務(wù)來(lái)說(shuō)似乎有點(diǎn)過(guò)于強(qiáng)大了.

                  The only thing I could find is using Celery, but this seems to be a bit overpower for the simple task I want to perform.

                  有什么簡(jiǎn)單的我可以做或者我必須使用 Celery 嗎?

                  Is there anything simple that i can do or do I have to use Celery?

                  推薦答案

                  目前我有一個(gè)函數(shù)(視圖)可以遍歷每個(gè) URL 以獲取信息,并更新數(shù)據(jù)庫(kù).

                  Currently I have a function (view) that go over each URL to get the information, and update the DB.

                  這意味著響應(yīng)時(shí)間對(duì)您來(lái)說(shuō)并不重要,而不是在后臺(tái)(異步)執(zhí)行,如果您的響應(yīng)時(shí)間減少 4(使用 4 個(gè)子進(jìn)程/線程),您可以在前臺(tái)執(zhí)行.如果是這種情況,您可以簡(jiǎn)單地將示例代碼放在您的視圖中.喜歡

                  It means response time does not matter for you and instead of doing it in the background (asynchronously), you are OK with doing it in the foreground if your response time is cut by 4 (using 4 sub-processes/threads). If that is the case you can simply put your sample code in your view. Like

                  from multiprocessing import Pool
                  
                  def updateDB(ip):
                       code goes here...
                  
                  def my_view(request):
                      pool = Pool(processes=4)              # process per core
                      pool.map(updateDB, ip)
                      return HttpResponse("SUCCESS")
                  

                  但是,如果您想在后臺(tái)異步執(zhí)行此操作,那么您應(yīng)該使用 Celery 或遵循@BasicWolf 的建議之一.

                  But, if you want to do it asynchronously in the background then you should use Celery or follow one of @BasicWolf's suggestions.

                  這篇關(guān)于如何在 django 視圖中使用 python 多處理模塊的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動(dòng)后進(jìn)度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動(dòng)時(shí),yaxis 刻度標(biāo)簽應(yīng)該可見(jiàn)
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時(shí)顯示進(jìn)度條?)
                  <tfoot id='ImFVC'></tfoot>

                    <legend id='ImFVC'><style id='ImFVC'><dir id='ImFVC'><q id='ImFVC'></q></dir></style></legend>

                      • <bdo id='ImFVC'></bdo><ul id='ImFVC'></ul>
                      • <i id='ImFVC'><tr id='ImFVC'><dt id='ImFVC'><q id='ImFVC'><span id='ImFVC'><b id='ImFVC'><form id='ImFVC'><ins id='ImFVC'></ins><ul id='ImFVC'></ul><sub id='ImFVC'></sub></form><legend id='ImFVC'></legend><bdo id='ImFVC'><pre id='ImFVC'><center id='ImFVC'></center></pre></bdo></b><th id='ImFVC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ImFVC'><tfoot id='ImFVC'></tfoot><dl id='ImFVC'><fieldset id='ImFVC'></fieldset></dl></div>

                            <tbody id='ImFVC'></tbody>

                          <small id='ImFVC'></small><noframes id='ImFVC'>

                            主站蜘蛛池模板: 久久久激情 | 日韩精品一区二区久久 | 91久久精品一区二区二区 | 91一区二区三区 | 国产激情在线 | 欧美三区视频 | 亚洲国产精品久久久久 | 亚洲视频一区在线播放 | 久久中文高清 | 日韩欧美国产一区二区三区 | 精品美女久久久久久免费 | 亚洲精品久久久蜜桃 | 日韩成人性视频 | 91网在线观看 | 天天操天天怕 | 国产精品日韩在线 | 色www精品视频在线观看 | 亚洲在线电影 | 91精品国产91久久久久久吃药 | 久久精品国产久精国产 | 91免费电影 | www.久久精品视频 | 国产一区二| 欧美日韩在线视频一区二区 | 久久精品视频播放 | 91亚洲国产精品 | 久久久精品 | 一区二区三区国产精品 | 美女久久久 | 国产欧美精品一区二区色综合朱莉 | 亚洲草草视频 | 欧美日韩在线视频一区二区 | av天天看| 国产精品色哟哟网站 | 欧美中文字幕在线观看 | 日韩视频精品 | 欧美成人aaa级毛片在线视频 | 日韩免费1区二区电影 | 中文字幕日本一区二区 | 欧美 视频 | 国产精品成人一区二区 |