Puas yog Python zoo rau kev sib txuam?
Puas yog Python zoo rau kev sib txuam?

Video: Puas yog Python zoo rau kev sib txuam?

Video: Puas yog Python zoo rau kev sib txuam?
Video: Maiv nyiaj nkauj 2024, Hlis ntuj nqeg
Anonim

Python tsis heev zoo rau CPU-bound ua ke programming. GIL yuav (ntau zaus) ua rau koj qhov kev pabcuam ua haujlwm zoo li nws tau khiav ntawm ib qho tseem ceeb - lossis tseem phem dua. Yog tias koj daim ntawv thov yog I / O-bound, Python tej zaum yuav yog ib qho kev daws teeb meem loj raws li GIL ib txwm tso tawm thaum ua thaiv kev hu.

Kuj paub yog, Python puas txhawb kev sib koom ua ke?

Python ua muaj cov tsev qiv ntawv built-in rau feem ntau ua ke programming constructs - multiprocessing thiab multithreading. Qhov laj thawj yog, multithreading hauv Python tsis yog multithreading tiag tiag, vim GIL hauv Python.

Ib tug kuj yuav nug, yog vim li cas multithreading tsis ua tau nyob rau hauv python? Tus neeg txhais lus CPython (rau ntshiab Python code) yuav yuam kom GIL tso tawm txhua pua byte cov lus qhia. Nws tsuas yog tso cai rau ib txoj xov los khiav ib zaug hauv tus neeg txhais lus. Yog li multiprocessing tsis multithreading yuav cia koj mus cuag qhov tseeb concurrency.

Tom qab ntawd, lo lus nug yog, Python puas zoo rau kev sib txuas lus?

Python tsis pub ntau txoj xov nyob rau hauv qhov tseeb ntawm lo lus. Nws muaj ib ntau txoj xov pob tab sis yog tias koj xav tau ntau xov kom ceev koj cov cai, ces feem ntau nws tsis yog zoo tswv yim siv nws. Python muaj ib lub tsev hu ua Global Interpreter Lock (GIL).

Cov module twg tuaj yeem siv los ua qhov sib txuam hauv Python 3?

Cov ua ke . yav tom ntej module tau ntxiv rau hauv Python 3.2. Raws li cov Python cov ntaub ntawv nws muab tus tsim tawm nrog rau theem siab interface rau asynchronously executing callables.

Pom zoo: