我想通过多处理使用池来发送文件,并且只打开一个FTP连接。 因此,我尝试使用下面的代码来做到这一点:
public function up()
{
Schema::create('contracts', function (Blueprint $table) {
$table->increments('id');
// Some other cols removed for this post
$table->integer('user_file_id')->unsigned();
$table->timestamps();
$table->foreign('user_file_id')->references('id')->on('user_files');
});
}
但是此代码执行错误,回溯在这里:
import multiprocessing
from ftplib import FTP
import os
import glob
ftp = FTP()
def ftp_upload(filename):
with open(filename, 'rb') as f:
ftp.storlines('STOR %s' % remote_path+filename, f)
def main():
while True:
if retry:
file_list=sorted(glob.glob('*.txt'))
pool = multiprocessing.Pool(processes=5)
pool.map(ftp_upload, file_list)
pool.close()
pool.join()
else:
ftp.connect('host', port)
ftp.login('login','pass')
if __name__ == '__main__':
main()