Python进程池处理数据

2019年5月15日 20:49 by wst

python高级

起因:

在处理程序的过程中,老是达不到要求的速度,比如昨天的数据还没处理完,今天的数据又来了。

 

解决方法:

采用的方法可以有多种,这里介绍下多进程。

为了防止启动过多进程而卡死机器,进程池是个不错的方案。

在设置进程池容量的时候,最好是和机器的核心数一样。

 

代码实例:

from multiprocessing import Pool
import time

def store_es2(**kwargs):
    source = kwargs.get("data_source", None)
    print("Now handling source:", source)
    time.sleep(10)
    return True


if __name__ == "__main__":
    t1 =time.time()
    p = Pool(4)
    S = ["source1", "source2", "source4", "source5", "source6"]
    for i in S:
        res = p.apply_async(store_es2, kwds={"data_source":i})
        print(res)
    p.close()
    p.join()
    print("use time:{:.3f}".format(time.time()-t1))
    print("done!")

 

输出:

$ python multipool.py 
<multiprocessing.pool.ApplyResult object at 0x7f75b88e4ac8>
<multiprocessing.pool.ApplyResult object at 0x7f75b88e4ba8>
<multiprocessing.pool.ApplyResult object at 0x7f75b88e4cc0>
Now handling source: source1
<multiprocessing.pool.ApplyResult object at 0x7f75b88e4d68>
<multiprocessing.pool.ApplyResult object at 0x7f75b88e4e10>
Now handling source: source2
Now handling source: source4
Now handling source: source5
Now handling source: source6
use time:20.053
done!

 

大家如有更好的方法,欢迎在下方留言,或加微信:wst_ccut


Comments(123) Add Your Comment

Charlesnag
“I haven’t seen you in these parts,” the barkeep said, sidling over to where I sat. “Designation’s Bao.” He stated it exuberantly, as if word of his exploits were shared by way of settlers hither many a ‚lan in Aeternum. He waved to a unanimated hogshead upset us, and I returned his token with a nod. He filled a telescope and slid it to me across the stained red wood of the bench prior to continuing. “As a betting fellow, I’d be assenting to wager a fair portion of enrich oneself you’re in Ebonscale Reach in search more than the wet one's whistle and sights,” he said, eyes glancing from the sword sheathed on my cool to the bend slung across my back. https://www.google.cl/url?sa=t&ct=es_cl/0-0&ei=AZt4RPyPKoz8oQLX5f3BAQ&url=https://renewworld.ru/sistemnye-trebovaniya-new-world/
Ncngnx
cost atorvastatin 20mg <a href="https://lipiws.top/">atorvastatin 20mg pills</a> lipitor 20mg generic
Exzwdc
buy cipro 1000mg - <a href="https://metroagyl.top/keflexcapsule/">keflex cheap</a> augmentin 625mg sale
Ixppjj
order ciprofloxacin pills - <a href="https://cipropro.top/gemyambutol/">ethambutol 1000mg brand</a> how to get clavulanate without a prescription
Yjleqz
order metronidazole 200mg online cheap - <a href="https://metroagyl.top/">buy metronidazole 400mg generic</a> azithromycin 500mg without prescription
Pcsful
ciprofloxacin usa - <a href="https://septrim.top/chloromycetin/">buy chloromycetin cheap</a> erythromycin 500mg ca
Anwumm
buy valtrex 500mg pill - <a href="https://gnantiviralp.com/zovirax/">order zovirax 800mg sale</a> oral zovirax 800mg
Imqifb
stromectol cream - <a href="https://keflexin.top/sumycin/">generic sumycin</a> cost tetracycline 250mg
Atyxbs
metronidazole 200mg brand - <a href="https://metroagyl.top/clindamycin/">order cleocin 150mg generic</a> where to buy azithromycin without a prescription
Lnxqpf
buy ampicillin no prescription <a href="https://ampiacil.top/">ampicillin over the counter</a> order amoxil sale
Kacbxh
buy lasix medication - <a href="https://antipathogenc.com/prograf/">order prograf 1mg sale</a> buy capoten without a prescription
Oappmu
retrovir 300 mg pill - <a href="https://canadiangnp.com/">buy glycomet 500mg online</a> order zyloprim 300mg for sale
Czhxqa
metformin uk - <a href="https://gnantiacidity.com/baycip/">buy ciprofloxacin 1000mg online cheap</a> buy lincocin 500mg without prescription
Ycfmdk
buy clozaril 100mg pill - <a href="https://genonlinep.com/altace/">ramipril 10mg price</a> pepcid 20mg uk
Qassjn
seroquel price - <a href="https://gnkantdepres.com/bupron/">bupron SR cost</a> eskalith pills
Tarcdq
hydroxyzine drug - <a href="https://antdepls.com/pamelor/">purchase pamelor without prescription</a> amitriptyline 25mg without prescription
Opvoki
anafranil tablet - <a href="https://antdeponline.com/">order anafranil online</a> cheap sinequan
Twiguc
purchase amoxicillin pill - <a href="https://atbioxotc.com/ceftin/">order generic axetil</a> buy cipro 1000mg generic
Ecnjzz
augmentin 375mg pills - <a href="https://atbioinfo.com/ethambutol/">ethambutol 600mg pill</a> ciprofloxacin 500mg pills
Npzqkg
where to buy cleocin without a prescription - <a href="https://cadbiot.com/doxycycline/">cheap doxycycline</a> buy chloromycetin generic
Ldjnos
buy azithromycin 250mg for sale - <a href="https://gncatbp.com/dofloxacin/">buy floxin no prescription</a> buy generic ciplox
Syiumb
albuterol over the counter - <a href="https://antxallergic.com/advairdiskus/">order advair diskus inhalator sale</a> order theo-24 Cr 400mg generic
Nmezhd
ivermectin 3mg over counter - <a href="https://antibpl.com/ascefaclor/">cefaclor 500mg uk</a> order cefaclor 250mg generic
Imgwkn
buy clarinex without a prescription - <a href="https://rxtallerg.com/flixotidespray/">buy generic flixotide over the counter</a> albuterol 4mg cost
Quakgs
buy depo-medrol without a prescription - <a href="https://ntallegpl.com/getazelastine/">astelin usa</a> astelin us
Eeemsq
order micronase - <a href="https://prodeprpl.com/pioglitazone30/">buy actos sale</a> order dapagliflozin 10mg
Ycyiny
prandin online - <a href="https://depressinfo.com/jardiance25/">buy empagliflozin 10mg without prescription</a> buy empagliflozin 25mg online
Xznuey
order metformin 500mg - <a href="https://arxdepress.com/acarbose50/">order precose for sale</a> acarbose 50mg pills
Bgmdck
how to buy terbinafine - <a href="https://treatfungusx.com/xgrifulvinvs/">grifulvin v online</a> how to buy griseofulvin
Ogrvkq
order rybelsus 14 mg pills - <a href="https://infodeppl.com/glucovance5/">order generic glucovance</a> buy cheap DDAVP
Lqqziz
buy nizoral 200mg pill - <a href="https://antifungusrp.com/itraconazole100/">itraconazole pill</a> itraconazole order
Cfznao
generic lanoxin - <a href="https://blpressureok.com/furosemidediuret/">furosemide 100mg ca</a> furosemide online
Pgglyq
famciclovir 500mg us - <a href="https://amvinherpes.com/">famciclovir 500mg canada</a> valaciclovir 1000mg cost
Jaxhgx
how to buy microzide - <a href="https://norvapril.com/felodipine/">felodipine 5mg canada</a> buy cheap generic bisoprolol
Qtruuy
buy lopressor tablets - <a href="https://bloodpresspl.com/">brand lopressor 100mg</a> nifedipine pills
Hclxmk
buy nitroglycerin generic - <a href="https://nitroproxl.com/indapamide/">lozol 1.5mg generic</a> buy generic diovan for sale
Sjizqm
crestor pills pursue - <a href="https://antcholesterol.com/">rosuvastatin pills latter</a> caduet swim
Nblcvi
zocor curiosity - <a href="https://canescholest.com/fenofibrate/">fenofibrate command</a> atorvastatin serve
Jaasab
buy viagra professional home - <a href="https://edsildps.com/cialisprofessional/">cialis professional absorb</a> levitra oral jelly online motion
Cpabva
cenforce solitary - <a href="https://xcenforcem.com/zenegrasildenafil/">zenegra online egg</a> brand viagra pills column
Dzornh
dapoxetine army - <a href="https://promedprili.com/zudena/">udenafil thousand</a> cialis with dapoxetine try
Rskbyh
brand cialis pile - <a href="https://probrandtad.com/alprostadilonline/">alprostadil over</a> penisole fang
Ycgbkf
cialis soft tabs online per - <a href="https://supervalip.com/tadarisepills/">tadarise new</a> viagra oral jelly border
Qnbaxt
brand cialis line - <a href="https://probrandtad.com/tadorapills/">tadora save</a> penisole dull
Jpaskq
cialis soft tabs pills keeper - <a href="https://supervalip.com/valifonline/">valif maid</a> viagra oral jelly best
Teoaeq
cenforce think - <a href="https://xcenforcem.com/cialistadalafil/">cialis active</a> brand viagra online frame
Zulelr
acne medication allow - <a href="https://placnemedx.com/">acne treatment uncomfortable</a> acne medication tread
Gqoxvi
uti medication against - <a href="https://amenahealthp.com/">uti medication remove</a> uti medication after
Ukdpkj
prostatitis pills slide - <a href="https://xprosttreat.com/">prostatitis treatment steward</a> prostatitis treatment frown
Uqyrgg
valtrex jam - <a href="https://gnantiviralp.com/">valacyclovir pills puff</a> valtrex awkward
Bfitny
loratadine medication employ - <a href="https://clatadine.top/">claritin pills brandy</a> claritin protect
Eoyjlf
loratadine joy - <a href="https://clatadine.top/">loratadine medication scatter</a> loratadine meet
Ujljfl
priligy alas - <a href="https://prilixgn.top/">priligy darkness</a> priligy russian
Jlzpdl
promethazine raft - <a href="https://prohnrg.com/">promethazine ocean</a> promethazine deep
Wocscj
ascorbic acid hair - <a href="https://ascxacid.com/">ascorbic acid slab</a> ascorbic acid needle
Cmbqdk
florinef depress - <a href="https://gastroplusp.com/omepprilosec/">omeprazole pills patrician</a> prevacid drum
Tyywsz
clarithromycin pills drain - <a href="https://gastropls.com/gncytotec/">cytotec pills fetch</a> cytotec pills whirl
Lkcawr
bisacodyl for sale online - <a href="https://gastroinfop.com/liv52/">purchase liv52 sale</a> liv52 10mg drug
Eodjfq
rabeprazole 10mg drug - <a href="https://gastrointesl.com/">order aciphex 10mg without prescription</a> buy motilium 10mg without prescription
Jtisag
bactrim 960mg brand - <a href="https://tobmycin.com/">buy tobrex</a> buy tobrex 10mg drops
Cfquuq
hydroquinone order - <a href="https://danaterone.shop/">where can i buy zovirax</a> buy duphaston 10mg for sale
Iwlbvb
forxiga 10mg us - <a href="https://sineqpin.com/">order sinequan 25mg sale</a> order precose for sale
Qozfzg
cost griseofulvin - <a href="https://gemfilopi.com/">gemfibrozil cost</a> gemfibrozil 300 mg cost
Yafjbc
enalapril order - <a href="https://vasolapril.com/">buy vasotec pills</a> order latanoprost
Ohmgyk
order dramamine 50 mg sale - <a href="https://prasilx.com/">order prasugrel 10mg online</a> where to buy risedronate without a prescription
Hycqtn
feldene 20 mg uk - <a href="https://rivastilons.com/">generic exelon</a> exelon 6mg pills
Upkbzc
buy etodolac no prescription - <a href="https://cilosetal.com/">buy generic pletal online</a> oral pletal 100mg
Upviyh
buy hydrea generic - <a href="https://hydroydrinfo.com/">hydrea usa</a> methocarbamol 500mg cheap
Gferyb
buy piracetam 800 mg without prescription - <a href="https://nootquin.com/">piracetam online buy</a> order sinemet 20mg online cheap
Lxauyd
norpace medication - <a href="https://anorpica.com/">norpace cheap</a> thorazine 100mg pills
Rblvms
purchase depakote for sale - <a href="https://adepamox.com/amiodarone/">order amiodarone 200mg online cheap</a> buy topamax 100mg pills
Ryotfe
buy cheap cytoxan - <a href="https://cycloxalp.com/">order cytoxan pill</a> order trimetazidine sale
Ejhvva
buy aldactone without prescription - <a href="https://aldantinep.com/dipyridamole/">order dipyridamole for sale</a> order revia 50 mg pill
Khnddu
zofran oral - <a href="https://azofarininfo.com/selegiline/">generic selegiline</a> ropinirole sale
Aeuuyb
order flexeril online cheap - <a href="https://abflequine.com/">cyclobenzaprine 15mg cost</a> enalapril 10mg usa
Uliblp
brand ascorbic acid - <a href="https://mdacidinfo.com/isosorbidedinitrate/">order isosorbide dinitrate generic</a> prochlorperazine without prescription
Abdjfx
buy durex gel sale - <a href="https://xalaplinfo.com/latanoprosteyedrops/">purchase xalatan generic</a> purchase zovirax eye drops
Tmxupb
buy arava 20mg pill - <a href="https://infohealthybones.com/alfacalcidol/">alfacip tablets</a> cheap cartidin sale
Qcmwjl
order rogaine - <a href="https://hairlossmedinfo.com/finasteridefinp/">purchase finpecia generic</a> proscar order online
Yvmkjw
tenormin 50mg ca - <a href="https://heartmedinfox.com/clopidogrel/">cheap clopidogrel</a> coreg over the counter
Uzrmqg
oral verapamil 240mg - <a href="https://infoheartdisea.com/valsartan/">valsartan 80mg tablet</a> how to buy tenoretic
Azstwu
cheap atorlip - <a href="https://infoxheartmed.com/">atorvastatin for sale</a> order bystolic 5mg online
Bztewg
lasuna canada - <a href="https://infoherbalmz.com/">buy lasuna tablets</a> himcolin online
Hmzwbj
gasex tablets - <a href="https://herbalinfomez.com/">order generic gasex</a> buy diabecon medication
Wysoae
buy speman no prescription - <a href="https://spmensht.com/finasteride/">fincar pills</a> cheap finasteride without prescription
Gseszi
norfloxacin order - <a href="https://gmenshth.com/confido/">confido online order</a> buy generic confido
Glgite
hytrin tablet - <a href="https://hymenmax.com/tamsulosin/">flomax pills</a> buy generic priligy for sale
Yezqux
buy lactulose for sale - <a href="https://duphalinfo.com/mentat/">brahmi cost</a> how to get betahistine without a prescription
Mupkhz
buy oxcarbazepine 600mg online cheap - <a href="https://trileoxine.com/levothyroxine/">cheap levothroid tablets</a> levothroid ca
Vzijcb
purchase imusporin online cheap - <a href="https://asimusxate.com/">buy cyclosporine no prescription</a> buy colcrys for sale
Plismp
cheap deflazacort pills - <a href="https://lazacort.com/brimonidine/">purchase brimonidine sale</a> buy generic alphagan online
Indecy
neurontin price - <a href="https://aneutrin.com/sulfasalazine/">azulfidine 500 mg oral</a> azulfidine 500 mg drug
Zkaqya
cost besivance - <a href="https://besifxcist.com/carbocysteine/">carbocisteine cost</a> sildamax oral
Trbjhv
purchase probalan online cheap - <a href="https://bendoltol.com/">purchase probenecid</a> order carbamazepine 200mg pills
Jqkzmx
celebrex online order - <a href="https://celespas.com/">purchase celecoxib for sale</a> order indomethacin 75mg sale
Ohiigw
brand mebeverine 135mg - <a href="https://coloxia.com/etoricoxib/">buy generic etoricoxib for sale</a> brand pletal 100 mg
Xdnece
buy diclofenac online - <a href="https://dicloltarin.com/aspirin/">order aspirin without prescription</a> buy aspirin generic
Cxomlk
order rumalaya - <a href="https://rumaxtol.com/amitriptyline/">endep 10mg uk</a> purchase endep generic
Dmneku
purchase mestinon online cheap - <a href="https://mestonsx.com/azathioprine/">azathioprine 25mg usa</a> order generic imuran
Xvqlzq
brand baclofen - <a href="https://baclion.com/">order generic lioresal</a> piroxicam 20 mg uk
Orrqpc
buy periactin 4 mg without prescription - <a href="https://periheptadn.com/">periactin online</a> buy generic tizanidine over the counter
Yrteah
buy mobic 7.5mg online - <a href="https://meloxiptan.com/asrizatriptan/">how to get rizatriptan without a prescription</a> purchase toradol online cheap
Lcvtia
buy omnicef 300 mg without prescription - <a href="https://omnixcin.com/aminocycline/"></a> cleocin generic
Fsjszb
purchase isotretinoin pill - <a href="https://aisotane.com/asavlosulfon/">avlosulfon pills</a> buy deltasone 5mg sale
Ludadg
where to buy prednisone without a prescription - <a href="https://apreplson.com/prednisolone/">omnacortil 10mg cost</a> elimite order
Dqkrig
buy generic acticin - <a href="https://actizacs.com/tretinoin/">buy tretinoin cream online</a> order tretinoin cream generic
Hfnqse
buy flagyl 200mg without prescription - <a href="https://cenforcevs.com/">cenforce 50mg pill</a> buy cenforce sale
Rjimhk
augmentin 625mg cost - <a href="https://baugipro.com/">clavulanate usa</a> cheap levothroid without prescription
Vjtzmy
order cleocin 300mg sale - <a href="https://clinycinpl.com/">cleocin without prescription</a> order indocin 50mg sale
Stsgau
hyzaar canada - <a href="https://cozartan.com/">cost cozaar 25mg</a> keflex 125mg pills
Tqpayj
crotamiton buy online - <a href="https://aeuracream.com/caczone/">order aczone pills</a> aczone usa
Hhqoem
buy generic modafinil - <a href="https://sleepagil.com/melatonin/">melatonin 3mg uk</a> meloset 3 mg generic
Ynxebq
buy bupropion 150 mg - <a href="https://bupropsl.com/shuddhaguggulu/">buy shuddha guggulu generic</a> shuddha guggulu oral
Zcfqvp
xeloda 500 mg cost - <a href="https://xelocap.com/danocrine/">order danazol 100mg online</a> danazol 100 mg ca
Dzjucr
prometrium 200mg cost - <a href="https://apromid.com/">buy generic progesterone</a> buy generic clomiphene
Elnqnb
buy fosamax 35mg online cheap - <a href="https://pilaxmax.com/pilex/">order pilex pills</a> buy provera paypal
Ppmabp
order norethindrone 5mg online - <a href="https://norethgep.com/yasmin/">yasmin tablets</a> purchase yasmin pill
Clagds
buy yasmin no prescription - <a href="https://festrolp.com/anastrozole/">arimidex 1mg pill</a> arimidex cheap
Ehhabo
oral dostinex - <a href="https://adostilin.com/cabgolin/">buy cabgolin for sale</a> alesse where to buy
Jbkyhc
プレドニン通販 - <a href="https://jpaonlinep.com/">プレドニン は通販での購</a> 正規品ジスロマック錠の正しい処方
Auetsb
シルデナフィル処方 - <a href="https://jpedpharm.com/">シルデナフィル通販 安全</a> タダラフィル 海外通販
Slvpwl
プレドニンの購入 - <a href="https://jpanfarap.com/jpaaccutane/">イソトレチノイン どこで買える</a> アキュテイン 薬局で買える
Uvvuwt
eriacta sullen - <a href="https://eriagra.com/">eriacta awful</a> forzest cut