該樓層疑似違規已被系統摺疊 隱藏此樓檢視此樓
# -*- coding: utf-8 -*-
import random
import threading
class mythread(threading.thread):
def __init__(self,func,args,name=''):
threading.thread.__init__(self);
self.name=name;
self.func=func;
self.args=args;
def run(self):
def downloadpic(pagenum):
#變數宣告
#建立迴圈
if(flag==1):
pagenum=int(pagenum)+threadnum;
else:
pagenum=int(pagenum);
print ("nextpage:%s"%pagenum)+"\n";
if(pagenum<=endnum):
downloadpic(pagenum);
if __name__=='__main__':
#建立執行緒
#可執行:base=[1,2,3,4,5];
#不可執行
base=[40,41,42,43,44];
threads=;
threadnum=len(base);
#分配執行緒
for urlnum in range(threadnum):
t=mythread(downloadpic,str(base[urlnum]),downloadpic.__name__);
#啟動執行緒
for tnum in range(threadnum):
threads[tnum].start();
#阻塞程序
for tnum in range(threadnum):
threads[tnum].join();
python執行緒問題 Python執行緒問題
我有以下內容 d a dictionary with strings l1 a list with stuff l2 a list with numbers for i in l1 for key in l2 do some stuff if d key i print d key 我想使用執行緒 ...
python 執行緒衝突問題
執行緒衝突問題 usr bin python coding utf 8 author fmspider time 2018 5 3 10 15 function 執行緒衝突 import threading def addnum global num num 1 tem num print ok n...
莫煩pytho學習之多執行緒
多執行緒是什麼呢?多執行緒是加速程式計算的有效方式,python的多執行緒模組threading上手快速簡單 新增執行緒 import threading defadding thread print this is new thread s threading.current thread def...