Python mutiprocessing 다 중 스 레 드 풀 작업 예제
7323 단어 Pythonmutiprocessing다 중 스 레 드
python―mutiprocessing 다 중 스 레 드 풀
스 크 립 트 코드:
root@72132server:~/python/multiprocess# ls
multiprocess_pool.py multprocess.py
root@72132server:~/python/multiprocess# cat multiprocess_pool.py
#!/usr/bin/python
# --*-- coding:utf-8 --*--
import multiprocessing
import sys,os,time
result = []# ,
def run(msg):#
print 'threading number:%s %s' %(msg,os.getpid())#
time.sleep(2)
p = multiprocessing.Pool(processes = 25)# , 25
for i in range(100):
result.append(p.apply_async(run,('%s' %i,)))#
p.close()# 25
#p.join()
for res in result:#
res.get(timeout=5)
root@72132server:~/python/multiprocess#
실행 상황:1)스 크 립 트 실행
root@72132server:~/python/multiprocess# python multiprocess_pool.py
threading number:0 27912
threading number:1 27915
threading number:2 27913
threading number:3 27916
threading number:4 27917
threading number:5 27918
threading number:6 27919
threading number:7 27920
threading number:8 27922
threading number:9 27923
threading number:10 27924
threading number:11 27925
threading number:12 27926
threading number:13 27927
threading number:14 27928
threading number:15 27914
threading number:16 27929
threading number:17 27921
threading number:18 27930
threading number:19 27931
threading number:20 27932
threading number:21 27934
threading number:22 27935
threading number:23 27936
threading number:24 27933
threading number:25 27912
threading number:26 27915
threading number:27 27917
threading number:28 27918
threading number:29 27916
threading number:30 27913
threading number:31 27922
threading number:32 27919
threading number:33 27920
threading number:34 27923
threading number:35 27924
threading number:36 27925
threading number:37 27927
threading number:38 27921
threading number:39 27930
threading number:40 27932
threading number:41 27934
threading number:42 27935
threading number:43 27926
threading number:44 27931
threading number:45 27928
threading number:46 27929
threading number:47 27914
threading number:48 27933
threading number:49 27936
threading number:50 27912
threading number:51 27915
2)프로 세 스 보기(25 개 프로 세 스 동시 실행)
root@72132server:~/python/multiprocess# ps -ef | grep multi
root 27905 23930 0 22:39 pts/3 00:00:00 grep multi
root@72132server:~/python/multiprocess# ps -ef | grep multi
root 27911 20609 1 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27912 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27913 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27914 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27915 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27916 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27917 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27918 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27919 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27920 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27921 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27922 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27923 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27924 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27925 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27926 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27927 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27928 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27929 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27930 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27931 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27932 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27933 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27934 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27935 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27936 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27941 23930 0 22:39 pts/3 00:00:00 grep multi
root@72132server:~/python/multiprocess# ps -ef | grep multi
root 27911 20609 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27912 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27913 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27914 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27915 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27916 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27917 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27918 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27919 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27920 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27921 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27922 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27923 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27924 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27925 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27926 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27927 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27928 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27929 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27930 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27931 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27932 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27933 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27934 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27935 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27936 27911 0 22:39 pts/1 00:00:00 python multiprocess_pool.py
root 27943 23930 0 22:39 pts/3 00:00:00 grep multi
root@72132server:~/python/multiprocess#
더 많은 파 이 썬 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.본 논문 에서 말 한 것 이 여러분 의 Python 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Python의 None과 NULL의 차이점 상세 정보그래서 대상 = 속성 + 방법 (사실 방법도 하나의 속성, 데이터 속성과 구별되는 호출 가능한 속성 같은 속성과 방법을 가진 대상을 클래스, 즉 Classl로 분류할 수 있다.클래스는 하나의 청사진과 같아서 하나의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.