SlideShare una empresa de Scribd logo
1 de 16
北京迅达云成科技有限公司 www.speedycloud.cn
北京迅达云成科技有限公司
www.speedycloud.cn
2015年9月 北京
WELCOME
How to Use Multi-thread &
Multi-process in Python
北京迅达云成科技有限公司 www.speedycloud.cn
Why using multi-thread?
Productivity
北京迅达云成科技有限公司 www.speedycloud.cn
Multi-thread Multi-process
Code
Review
北京迅达云成科技有限公司 www.speedycloud.cn
You Got Me!
北京迅达云成科技有限公司 www.speedycloud.cn
What is GIL?
In C-python, the global interpreter lock, or GIL, is a mutex that
prevents multiple native threads from executing Python byte-codes at
once. This lock is necessary mainly because C-Python’s memory
management is not thread-safe.(However, since the GIL exists, other
features have grown to depend on the guarantees that it enforces.)
GIL will serialize threads and stop the concurrence of threads.
北京迅达云成科技有限公司 www.speedycloud.cn
Multi-thread test
北京迅达云成科技有限公司 www.speedycloud.cn
Python multi-thread, no use at all?
NO!
北京迅达云成科技有限公司 www.speedycloud.cn
The Good News…
I/O Intensive:
北京迅达云成科技有限公司 www.speedycloud.cn
IO Intensive Running Sequence
北京迅达云成科技有限公司 www.speedycloud.cn
Unfortunately…
CPU Intensive Task: Multi-thread’s
productivity even worse than single thread
北京迅达云成科技有限公司 www.speedycloud.cn
How to deal with it?
First:
Ctypes
北京迅达云成科技有限公司 www.speedycloud.cn
Second:
multiprocessing
Extra:multiprocessing.dummy
How to deal with it?
北京迅达云成科技有限公司 www.speedycloud.cn
Been there, done that…
Join()
北京迅达云成科技有限公司 www.speedycloud.cn
file discripter
In Linux, all operations on all devices and/or files are done via file descriptor.
Been there, done that…
北京迅达云成科技有限公司 www.speedycloud.cn
北京迅达云成科技有限公司 www.speedycloud.cn
Thanks!
Beijing SpeedyCloud Technology Co., Ltd.,
www.speedycloud.cn

Más contenido relacionado

Similar a How to Use Multi-thread & Multi-process in Python

Build Smart Service on GCP - Google DevFest 2018 Taiwan
Build Smart Service on GCP - Google DevFest 2018 TaiwanBuild Smart Service on GCP - Google DevFest 2018 Taiwan
Build Smart Service on GCP - Google DevFest 2018 TaiwanDavid Chen
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSCisco Russia
 
Performance Enhancement Tips
Performance Enhancement TipsPerformance Enhancement Tips
Performance Enhancement TipsTim (文昌)
 
Pycon11: Python threads: Dive into GIL!
Pycon11: Python threads: Dive into GIL!Pycon11: Python threads: Dive into GIL!
Pycon11: Python threads: Dive into GIL!Chetan Giridhar
 
MQTT with Eclipse Paho: A protocol for IoT and M2M communication
MQTT with Eclipse Paho: A protocol for IoT and M2M communicationMQTT with Eclipse Paho: A protocol for IoT and M2M communication
MQTT with Eclipse Paho: A protocol for IoT and M2M communicationChristian Götz
 
Beego meetup 4.4.2017 @ Gett
Beego meetup 4.4.2017 @ GettBeego meetup 4.4.2017 @ Gett
Beego meetup 4.4.2017 @ GettBoris Borshevsky
 
GIL - Concurrency & Parallelism in Python
GIL - Concurrency & Parallelism in PythonGIL - Concurrency & Parallelism in Python
GIL - Concurrency & Parallelism in PythonPiyus Gupta
 
Advanced topics with python
Advanced topics with pythonAdvanced topics with python
Advanced topics with pythonsaipreethi16
 
Advanced topics with python
Advanced topics with pythonAdvanced topics with python
Advanced topics with pythonsaijohn1997
 
Understanding Non Blocking I/O with Python
Understanding Non Blocking I/O with PythonUnderstanding Non Blocking I/O with Python
Understanding Non Blocking I/O with PythonVaidik Kapoor
 
Biscuit, the cryptotoken you can share safely with your ap is
Biscuit, the cryptotoken you can share safely with your ap isBiscuit, the cryptotoken you can share safely with your ap is
Biscuit, the cryptotoken you can share safely with your ap isQuentin Adam
 
Interconnection Automation For All - GPF 2023
Interconnection Automation For All - GPF 2023Interconnection Automation For All - GPF 2023
Interconnection Automation For All - GPF 2023Chris Grundemann
 
Production ready kubernetes
Production ready kubernetesProduction ready kubernetes
Production ready kubernetesArnaud MAZIN
 
A Ci Experience
A Ci ExperienceA Ci Experience
A Ci ExperienceUmut IŞIK
 
Securing an NGINX deployment for K8s
Securing an NGINX deployment for K8sSecuring an NGINX deployment for K8s
Securing an NGINX deployment for K8sDevOps Indonesia
 
Cilium + Istio with Gloo Mesh
Cilium + Istio with Gloo MeshCilium + Istio with Gloo Mesh
Cilium + Istio with Gloo MeshChristian Posta
 
Delivering Quality at Speed with GitOps
Delivering Quality at Speed with GitOpsDelivering Quality at Speed with GitOps
Delivering Quality at Speed with GitOpsWeaveworks
 
GitOps and security by Reto Bollinger, CSIO nine.ch
GitOps and security by Reto Bollinger, CSIO nine.chGitOps and security by Reto Bollinger, CSIO nine.ch
GitOps and security by Reto Bollinger, CSIO nine.chnine
 
What's happening in the OSGi IoT Expert Group? - Tim Ward
What's happening in the OSGi IoT Expert Group? - Tim WardWhat's happening in the OSGi IoT Expert Group? - Tim Ward
What's happening in the OSGi IoT Expert Group? - Tim Wardmfrancis
 

Similar a How to Use Multi-thread & Multi-process in Python (20)

Build Smart Service on GCP - Google DevFest 2018 Taiwan
Build Smart Service on GCP - Google DevFest 2018 TaiwanBuild Smart Service on GCP - Google DevFest 2018 Taiwan
Build Smart Service on GCP - Google DevFest 2018 Taiwan
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
 
Performance Enhancement Tips
Performance Enhancement TipsPerformance Enhancement Tips
Performance Enhancement Tips
 
Pycon11: Python threads: Dive into GIL!
Pycon11: Python threads: Dive into GIL!Pycon11: Python threads: Dive into GIL!
Pycon11: Python threads: Dive into GIL!
 
MQTT with Eclipse Paho: A protocol for IoT and M2M communication
MQTT with Eclipse Paho: A protocol for IoT and M2M communicationMQTT with Eclipse Paho: A protocol for IoT and M2M communication
MQTT with Eclipse Paho: A protocol for IoT and M2M communication
 
Beego meetup 4.4.2017 @ Gett
Beego meetup 4.4.2017 @ GettBeego meetup 4.4.2017 @ Gett
Beego meetup 4.4.2017 @ Gett
 
GIL - Concurrency & Parallelism in Python
GIL - Concurrency & Parallelism in PythonGIL - Concurrency & Parallelism in Python
GIL - Concurrency & Parallelism in Python
 
Advanced topics with python
Advanced topics with pythonAdvanced topics with python
Advanced topics with python
 
Advanced topics with python
Advanced topics with pythonAdvanced topics with python
Advanced topics with python
 
Understanding Non Blocking I/O with Python
Understanding Non Blocking I/O with PythonUnderstanding Non Blocking I/O with Python
Understanding Non Blocking I/O with Python
 
Biscuit, the cryptotoken you can share safely with your ap is
Biscuit, the cryptotoken you can share safely with your ap isBiscuit, the cryptotoken you can share safely with your ap is
Biscuit, the cryptotoken you can share safely with your ap is
 
Interconnection Automation For All - GPF 2023
Interconnection Automation For All - GPF 2023Interconnection Automation For All - GPF 2023
Interconnection Automation For All - GPF 2023
 
Production ready kubernetes
Production ready kubernetesProduction ready kubernetes
Production ready kubernetes
 
A Ci Experience
A Ci ExperienceA Ci Experience
A Ci Experience
 
Securing an NGINX deployment for K8s
Securing an NGINX deployment for K8sSecuring an NGINX deployment for K8s
Securing an NGINX deployment for K8s
 
Tales from the OSGi trenches
Tales from the OSGi trenchesTales from the OSGi trenches
Tales from the OSGi trenches
 
Cilium + Istio with Gloo Mesh
Cilium + Istio with Gloo MeshCilium + Istio with Gloo Mesh
Cilium + Istio with Gloo Mesh
 
Delivering Quality at Speed with GitOps
Delivering Quality at Speed with GitOpsDelivering Quality at Speed with GitOps
Delivering Quality at Speed with GitOps
 
GitOps and security by Reto Bollinger, CSIO nine.ch
GitOps and security by Reto Bollinger, CSIO nine.chGitOps and security by Reto Bollinger, CSIO nine.ch
GitOps and security by Reto Bollinger, CSIO nine.ch
 
What's happening in the OSGi IoT Expert Group? - Tim Ward
What's happening in the OSGi IoT Expert Group? - Tim WardWhat's happening in the OSGi IoT Expert Group? - Tim Ward
What's happening in the OSGi IoT Expert Group? - Tim Ward
 

Más de SpeedyCloud

教育交互直播的技术难点与架构探索 @ 见云沙龙
教育交互直播的技术难点与架构探索 @ 见云沙龙教育交互直播的技术难点与架构探索 @ 见云沙龙
教育交互直播的技术难点与架构探索 @ 见云沙龙SpeedyCloud
 
选型指南:Cdn系统中dns的设计与研发
选型指南:Cdn系统中dns的设计与研发选型指南:Cdn系统中dns的设计与研发
选型指南:Cdn系统中dns的设计与研发SpeedyCloud
 
浅析Python多线程与多进程的使用
浅析Python多线程与多进程的使用浅析Python多线程与多进程的使用
浅析Python多线程与多进程的使用SpeedyCloud
 
运维?KVM & OpenVZ & Docker
运维?KVM & OpenVZ & Docker运维?KVM & OpenVZ & Docker
运维?KVM & OpenVZ & DockerSpeedyCloud
 
深入Docker的资源管理
深入Docker的资源管理深入Docker的资源管理
深入Docker的资源管理SpeedyCloud
 
Resource Management of Docker
Resource Management of DockerResource Management of Docker
Resource Management of DockerSpeedyCloud
 
The Evolution of SpeedyCloud Resources Scheduling System
The Evolution of  SpeedyCloud Resources Scheduling SystemThe Evolution of  SpeedyCloud Resources Scheduling System
The Evolution of SpeedyCloud Resources Scheduling SystemSpeedyCloud
 
SpeedyCloud 云计算平台资源调度系统要点解析
SpeedyCloud 云计算平台资源调度系统要点解析SpeedyCloud 云计算平台资源调度系统要点解析
SpeedyCloud 云计算平台资源调度系统要点解析SpeedyCloud
 

Más de SpeedyCloud (8)

教育交互直播的技术难点与架构探索 @ 见云沙龙
教育交互直播的技术难点与架构探索 @ 见云沙龙教育交互直播的技术难点与架构探索 @ 见云沙龙
教育交互直播的技术难点与架构探索 @ 见云沙龙
 
选型指南:Cdn系统中dns的设计与研发
选型指南:Cdn系统中dns的设计与研发选型指南:Cdn系统中dns的设计与研发
选型指南:Cdn系统中dns的设计与研发
 
浅析Python多线程与多进程的使用
浅析Python多线程与多进程的使用浅析Python多线程与多进程的使用
浅析Python多线程与多进程的使用
 
运维?KVM & OpenVZ & Docker
运维?KVM & OpenVZ & Docker运维?KVM & OpenVZ & Docker
运维?KVM & OpenVZ & Docker
 
深入Docker的资源管理
深入Docker的资源管理深入Docker的资源管理
深入Docker的资源管理
 
Resource Management of Docker
Resource Management of DockerResource Management of Docker
Resource Management of Docker
 
The Evolution of SpeedyCloud Resources Scheduling System
The Evolution of  SpeedyCloud Resources Scheduling SystemThe Evolution of  SpeedyCloud Resources Scheduling System
The Evolution of SpeedyCloud Resources Scheduling System
 
SpeedyCloud 云计算平台资源调度系统要点解析
SpeedyCloud 云计算平台资源调度系统要点解析SpeedyCloud 云计算平台资源调度系统要点解析
SpeedyCloud 云计算平台资源调度系统要点解析
 

Último

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Último (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

How to Use Multi-thread & Multi-process in Python