導航:首頁 > 編程語言 > pythonftplib多線程

pythonftplib多線程

發布時間:2022-03-01 04:13:00

python ftplib 傳輸文件大小的文件,如何傳輸較大文件

沒有矛盾啊。只要你不一口氣將所有文件都載入到內存里去。使用FTP協議,發送大文件不成問題。

FTP協議是個很簡單的協議。你可以仔細看一下原理。然後再配合python的ftplib看。你會發現那些cmd就是FTP的命令

❷ python復雜操作ftp的庫有哪些

Python提供內置操作ftp模塊ftplib 能夠完ftp登錄、查看目錄、修改目錄、傳文件等功能 般需求應該足

❸ Python 多線程編程問題

self.results[k]=fun(*args)這樣的用法是錯的,self.results本身就不是一個列表,就算是列表這樣的寫法也是錯的,假設上述的res=[],那麼存值的話,使用self.result.append(fun(*args)),我的代碼測試是正常的,可以試試。
from threading import Thread
class pyThread(Thread):
def __init__(self,funs,args,res=[]):
Thread.__init__(self)
self.funs=funs
self.args=args
self.results=res
def run(self):
for k,fun in enumerate(self.funs):
args=self.args[k]
self.results.append(fun(*args))
def getResult(self):
return self.results
th=pyThread([lambda x:x+1,lambda x:x*2],[(2,),(3,)])
th.start()
print th.getResult()

❹ ftp可否實現多線程上傳

沒有FTP軟體可以滿足你的要求。因為FTP協議里沒有給你多線程上傳的辦法。

❺ python 多進程和多線程配合

由於python的多線程中存在PIL鎖,因此python的多線程不能利用多核,那麼,由於現在的計算機是多核的,就不能充分利用計算機的多核資源。但是python中的多進程是可以跑在不同的cpu上的。因此,嘗試了多進程+多線程的方式,來做一個任務。比如:從中科大的鏡像源中下載多個rpm包。
#!/usr/bin/pythonimport reimport commandsimport timeimport multiprocessingimport threadingdef download_image(url):
print '*****the %s rpm begin to download *******' % url
commands.getoutput('wget %s' % url)def get_rpm_url_list(url):
commands.getoutput('wget %s' % url)
rpm_info_str = open('index.html').read()

regu_mate = '(?<=<a href=")(.*?)(?=">)'
rpm_list = re.findall(regu_mate, rpm_info_str)

rpm_url_list = [url + rpm_name for rpm_name in rpm_list] print 'the count of rpm list is: ', len(rpm_url_list) return rpm_url_
def multi_thread(rpm_url_list):
threads = [] # url = 'https://mirrors.ustc.e.cn/centos/7/os/x86_64/Packages/'
# rpm_url_list = get_rpm_url_list(url)
for index in range(len(rpm_url_list)): print 'rpm_url is:', rpm_url_list[index]
one_thread = threading.Thread(target=download_image, args=(rpm_url_list[index],))
threads.append(one_thread)

thread_num = 5 # set threading pool, you have put 4 threads in it
while 1:
count = min(thread_num, len(threads)) print '**********count*********', count ###25,25,...6707%25

res = [] for index in range(count):
x = threads.pop()
res.append(x) for thread_index in res:
thread_index.start() for j in res:
j.join() if not threads:
def multi_process(rpm_url_list):
# process num at the same time is 4
process = []
rpm_url_group_0 = []
rpm_url_group_1 = []
rpm_url_group_2 = []
rpm_url_group_3 = [] for index in range(len(rpm_url_list)): if index % 4 == 0:
rpm_url_group_0.append(rpm_url_list[index]) elif index % 4 == 1:
rpm_url_group_1.append(rpm_url_list[index]) elif index % 4 == 2:
rpm_url_group_2.append(rpm_url_list[index]) elif index % 4 == 3:
rpm_url_group_3.append(rpm_url_list[index])
rpm_url_groups = [rpm_url_group_0, rpm_url_group_1, rpm_url_group_2, rpm_url_group_3] for each_rpm_group in rpm_url_groups:
each_process = multiprocessing.Process(target = multi_thread, args = (each_rpm_group,))
process.append(each_process) for one_process in process:
one_process.start() for one_process in process:
one_process.join()# for each_url in rpm_url_list:# print '*****the %s rpm begin to download *******' %each_url## commands.getoutput('wget %s' %each_url)
def main():
url = 'https://mirrors.ustc.e.cn/centos/7/os/x86_64/Packages/'
url_paas = 'http://mirrors.ustc.e.cn/centos/7.3.1611/paas/x86_64/openshift-origin/'
url_paas2 ='http://mirrors.ustc.e.cn/fedora/development/26/Server/x86_64/os/Packages/u/'

start_time = time.time()
rpm_list = get_rpm_url_list(url_paas) print multi_process(rpm_list) # print multi_thread(rpm_list)
#print multi_process()
# print multi_thread(rpm_list)
# for index in range(len(rpm_list)):
# print 'rpm_url is:', rpm_list[index]
end_time = time.time() print 'the download time is:', end_time - start_timeprint main()123456789101112131415161718

代碼的功能主要是這樣的:
main()方法中調用get_rpm_url_list(base_url)方法,獲取要下載的每個rpm包的具體的url地址。其中base_url即中科大基礎的鏡像源的地址,比如:http://mirrors.ustc.e.cn/centos/7.3.1611/paas/x86_64/openshift-origin/,這個地址下有幾十個rpm包,get_rpm_url_list方法將每個rpm包的url地址拼出來並返回。
multi_process(rpm_url_list)啟動多進程方法,在該方法中,會調用多線程方法。該方法啟動4個多進程,將上面方法得到的rpm包的url地址進行分組,分成4組,然後每一個組中的rpm包再最後由不同的線程去執行。從而達到了多進程+多線程的配合使用。
代碼還有需要改進的地方,比如多進程啟動的進程個數和rpm包的url地址分組是硬編碼,這個還需要改進,畢竟,不同的機器,適合同時啟動的進程個數是不同的。

❻ python多線程老是報錯。大神幫忙看看哈

你好,你具體的代碼我沒看,但單從報錯來看,你的變數名寫錯了:
你定義的是
condition = threading.Condition()
但你第10行引用的是
conditon
少了一個字母i

❼ FTP伺服器可以使用多線程嗎

可以的,就好比可以同時使用多個匿名用戶是一樣的,只受你ftp最大連接數的限制,希望對你有幫助。

❽ python ftplib buffersize多大比較合理

沒有矛盾埃只要你不一口氣將所有文件都載入到內存里去。使用FTP協議,發送大文件不成問題。FTP協議是個很簡單的協議。你可以仔細看一下原理。然後再配合python的ftplib看。你會發現那些cmd就是FTP的命令。

❾ python多線程中每個線程如果不加休眠時間就會只泡在一個線程上,這該如何處理謝謝

這是三個線程都在跑啊,只是並發的而已

❿ python 操作ftp 都有哪些庫

Python提供了一個內置的操作ftp的模塊ftplib,
能夠完成ftp登錄、查看目錄、修改目錄、上傳文件等功能。
一般需求應該足夠了。

閱讀全文

與pythonftplib多線程相關的資料

熱點內容
優信二手車解壓後過戶 瀏覽:63
Windows常用c編譯器 瀏覽:780
關於改善國家網路安全的行政命令 瀏覽:835
安卓如何下載網易荒野pc服 瀏覽:656
javainetaddress 瀏覽:106
蘋果4s固件下載完了怎麼解壓 瀏覽:1005
命令zpa 瀏覽:288
python編譯器小程序 瀏覽:946
在app上看視頻怎麼光線調暗 瀏覽:542
可以中文解壓的解壓軟體 瀏覽:595
安卓卸載組件應用怎麼安裝 瀏覽:915
使用面向對象編程的方式 瀏覽:341
程序員項目經理的年終總結範文 瀏覽:932
內衣的加密設計用來幹嘛的 瀏覽:435
淮安數據加密 瀏覽:295
魔高一丈指標源碼 瀏覽:984
松下php研究所 瀏覽:170
c回調java 瀏覽:402
夢幻端游長安地圖互通源碼 瀏覽:747
電腦本地文件如何上傳伺服器 瀏覽:315