我正在通过python中的分块上传文件,其中docker network create --opt encrypted --driver overlay --attachable my-attachable-multi-host-network
用于http请求,requests
用于线程。我注意到32位和64位python 3.7之间存在一些不协调的行为,并希望对我做错的事情进行澄清。
我正在Windows 10计算机上运行。
所说的不协调行为涉及线程执行,该线程执行以32位为早,但以64位为宜。每当我有相对较多的线程(16),散布在相对较大的块以进行上传(52)时,似乎就会发生这种情况。
每当我以某种倾斜的方式等待任务时,我都能获得64位和32位的一致表现。参见下面的代码。
我定义的一些功能
concurrent.futures
我的上传代码有问题
def read_specific_chunk(file_path, chunk_disposition, chunk_size=CHUNK_SIZE_IN_BYTES):
file_handle = open(file_path, 'rb') # spawn new file handle for thread safe seek
file_handle.seek(chunk_disposition * chunk_size)
data = file_handle.read(chunk_size)
file_handle.close()
return data
def upload_chunk(chunk_position, file_transfer):
file_chunk = read_specific_chunk(FILE_PATH, # NOTE HOW THIS DEPENDS ON FILE PATH
chunk_position)
print(" Uploading chunk " + str(chunk_position + 1) + " of " + str(len(file_transfer.chunks)))
place_chunk_url = CHUNK_PUT_URL.replace("#", str(file_transfer.fileTransferId)).replace("$", str(chunk_position))
chunk_put_response = requests.put(url=place_chunk_url,
data=file_chunk,
headers=PUT_CHUNK_HEADERS,
auth=HttpNegotiateAuth())
if 200 <= chunk_put_response.status_code < 300:
print(" PUT chunk " + str(chunk_position + 1) + " of " + str(
len(file_transfer.chunks)) + " successfully for file transfer " + str(file_transfer.fileTransferId))
return True
print(" PUT " + str(chunk_position + 1) + " of " + str(len(file_transfer.chunks)) +
" FAILED with status code " + str(chunk_put_response.status_code) + " for file transfer " + str(
file_transfer.fileTransferId))
return False
我的64/32始终显示上传代码
with concurrent.futures.ThreadPoolExecutor(THREAD_COUNT) as executor:
for chunkPosition in range(0, len(fileTransfer.chunks)):
executor.submit(upload_chunk, chunkPosition, fileTransfer)
我希望每个块都可以通过有问题的代码在32位和64位python上上传。但是,似乎某些线程并未在32位python中执行。也不会引发可见错误。