SlideShare a Scribd company logo
北京迅达云成科技有限公司 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

More Related Content

Similar to 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 Taiwan
David Chen
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
Cisco Russia
 
Performance Enhancement Tips
Performance Enhancement TipsPerformance Enhancement Tips
Performance Enhancement Tips
Tim (文昌)
 
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 communication
Christian Götz
 
Beego meetup 4.4.2017 @ Gett
Beego meetup 4.4.2017 @ GettBeego meetup 4.4.2017 @ Gett
Beego meetup 4.4.2017 @ Gett
Boris Borshevsky
 
GIL - Concurrency & Parallelism in Python
GIL - Concurrency & Parallelism in PythonGIL - Concurrency & Parallelism in Python
GIL - Concurrency & Parallelism in Python
Piyus Gupta
 
Advanced topics with python
Advanced topics with pythonAdvanced topics with python
Advanced topics with python
saipreethi16
 
Advanced topics with python
Advanced topics with pythonAdvanced topics with python
Advanced topics with python
saijohn1997
 
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
Vaidik 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 is
Quentin Adam
 
Interconnection Automation For All - GPF 2023
Interconnection Automation For All - GPF 2023Interconnection Automation For All - GPF 2023
Interconnection Automation For All - GPF 2023
Chris Grundemann
 
Production ready kubernetes
Production ready kubernetesProduction ready kubernetes
Production ready kubernetes
Arnaud MAZIN
 
A Ci Experience
A Ci ExperienceA Ci Experience
A Ci Experience
Umut IŞIK
 
Securing an NGINX deployment for K8s
Securing an NGINX deployment for K8sSecuring an NGINX deployment for K8s
Securing an NGINX deployment for K8s
DevOps Indonesia
 
Tales from the OSGi trenches
Tales from the OSGi trenchesTales from the OSGi trenches
Tales from the OSGi trenches
Bertrand Delacretaz
 
Cilium + Istio with Gloo Mesh
Cilium + Istio with Gloo MeshCilium + Istio with Gloo Mesh
Cilium + Istio with Gloo Mesh
Christian Posta
 
Delivering Quality at Speed with GitOps
Delivering Quality at Speed with GitOpsDelivering Quality at Speed with GitOps
Delivering Quality at Speed with GitOps
Weaveworks
 
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
nine
 
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
mfrancis
 

Similar to 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
 

More from 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 & Docker
SpeedyCloud
 
深入Docker的资源管理
深入Docker的资源管理深入Docker的资源管理
深入Docker的资源管理
SpeedyCloud
 
Resource Management of Docker
Resource Management of DockerResource Management of Docker
Resource Management of Docker
SpeedyCloud
 
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 云计算平台资源调度系统要点解析
SpeedyCloud 云计算平台资源调度系统要点解析
SpeedyCloud
 

More from 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 云计算平台资源调度系统要点解析
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 

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