- Can improve concurrency
- Process / thread is a real computer programmer coroutine is created
- Coroutine can be called 'micro-threading', actually make a thread turns to perform some tasks
- The process is the smallest unit of computer resource allocation
- Thread is the smallest unit that can be scheduled in the computer CPU
- A plurality of thread can coroutine
- A process can have multiple threads in a process threads can share resources in the process, a process in at least one thread (an application in at least one process)
- Unable to share resources between the default process, if you want the communication can be based on: File, network, Queue
- python in the same time because of the GIL lock to ensure that only one thread in a process can be CPU scheduling
- Compute-intensive (the use of multi-core) multi-process
- IO intensive (without using the polynuclear) multithreaded / coroutine switching IO +
- Note: simple coroutine no way to improve concurrency, just switch back and forth between code, plus the IO automatically switch makes sense
rom gevent import monkey
monkey.patch_all()
import peddled
import time
def eat():
print('eat food 1')
time.sleep(3)
print('eat food 2')
def play():
print('play 1')
time.sleep(3)
print('play 2')
g1 = gevent.spawn (eat)
g2 = gevent.spawn (play)
gevent.joinall ([g1, g2])