python - 将函数中的循环设置为不同的线程python
问题描述
如果我有一个循环将一个大文件发送到服务器,并且我仍然想通过相同的函数和套接字向服务器发送信息而不中断文件发送,我将如何设置循环在不同的线程或进程上运行
def sendtoserver():
# send a string here without interrupting
while not flsize == 0: # while loop multithread
with open(fp, "rb") as f:
for _ in progress:
# read the bytes from the file
bytes_read = f.read(flsize)
bytes_read_small = f.read(flsize)
if not bytes_read:
# file transmitting is done
break
self.s.sendall(bytes_read)
# update the progress bar
progress.update(len(bytes_read))
global file_sent
file_sent = 1
flsize = 1
self.s.shutdown()
self.s.close()
解决方案
推荐阅读
- python - 在 Keras 训练期间打印损失值
- jenkins - 构建标签时,Jenkins 管道会编译两次吗?
- angular - Google Charts DataTable 在 .NET Core 和 Angular 版本升级后不再工作
- python - 更新 Spider 和 Anaconda 后出现关键错误
- android - 如何解决 Xamarin.Android.Common.targets: 错误 MSB6006: "java.exe" exited with code 1
- javascript - 将 ajax 调用中的 html 附加到 shadow DOM
- azure - Azure 管道不会从具有单个 azure-pipelines.yml 文件的分支触发
- angular - 组件更新值时指令@Input 变量未得到更新
- python-3.x - 试图从另一个类访问一个类
- python - joblib 转储写入 0 字节文件