다음 두 가지 버전의 코드는 eventlet을 사용합니다. 두 개의 spawn_n 호출이 동시에 실행될 것으로 예상되지만 그 경우는 아닙니다. 실행은 순차적으로 발생합니다.Python Eventlet의 스폰 결과가 동시에 실행되지 않습니다
import eventlet
import threading
import datetime
from eventlet.green import urllib2
def hello(name):
print eventlet.greenthread.getcurrent(), threading.current_thread()
print datetime.datetime.now()
print " %s hello !!" % name
urllib2.urlopen("http://www.google.com/intl/en_ALL/images/logo.gif").read()
eventlet.spawn(hello, 'abc')
eventlet.spawn(hello, 'xyz')
eventlet.sleep(0)
는 는 O/P
: < _MainThread (MainThread가 시작 140365670881088)>
2016년 8월 9일 14 : 04 : 57.782866
ABC 안녕하십니까! 05 :
< _MainThread>
2016년 8월 9일 14 (MainThread가 시작 140365670881088) 02.929903
XYZ 안녕하세요!
import eventlet
import threading
import datetime
from eventlet.green import urllib2
def hello(name):
print eventlet.greenthread.getcurrent(), threading.current_thread()
print datetime.datetime.now()
print " %s hello !!" % name
urllib2.urlopen("http://www.google.com/intl/en_ALL/images/logo.gif").read()
pool = eventlet.GreenPool(size=4)
pool.spawn_n(hello, 'pqr')
pool.spawn_n(hello, 'lmn')
pool.waitall()
는 는 O/P
: 05 : < _MainThread>
2016년 8월 9일 14 (MainThread가 시작 139,897,149,990,720) 25.613546
PQR 안녕하십니까!
< _MainThread (MainThread가 시작 139,897,149,990,720)>
2016년 8월 9일 14 : 05 : 30.699473
LMN 안녕하십니까!
두 버전의 코드에서 호출은 순차적으로 발생합니다.
내가 다른 eventlet.spawn_n (안녕하세요, 'DEF') 또는 poll.spawn_n를 추가 한 후 (안녕하세요, '처음'). 마지막 2 번의 호출은 몇 밀리 초의 차이로 발생합니다. 문서화 시점에서, eventlet은 순전히 동시 적이 아닙니다. 어쨌든 매우 적은 수정으로 실제 동시 실행 방식이 있습니까? – nebi
'concurrently'를 정의하고 '순차적'과 어떻게 다른지 정의하십시오. – temoto