• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python 多线程实例详解

Python 多线程实例详解

作者:lqh 字体:[增加 减小] 来源:互联网

lqh 通过本文主要向大家介绍了python多线程实例,python 多线程,python多线程编程,python 线程,python创建线程等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Python 多线程实例详解

多线程通常是新开一个后台线程去处理比较耗时的操作,Python做后台线程处理也是很简单的,今天从官方文档中找到了一个Demo.

实例代码:

import threading, zipfile 
 
class AsyncZip(threading.Thread): 
  def __init__(self, infile, outfile): 
    threading.Thread.__init__(self) 
    self.infile = infile 
    self.outfile = outfile 
  def run(self): 
    f = zipfile.ZipFile(self.outfile, 'w', zipfile.ZIP_DEFLATED) 
    f.write(self.infile) 
    f.close() 
    print('Finished background zip of:', self.infile) 
 
background = AsyncZip('mydata.txt', 'myarchive.zip') 
background.start() 
print('The main program continues to run in foreground.') 
 
background.join()  # Wait for the background task to finish 
print('Main program waited until background was done.') 
</div>

结果:

The main program continues to run in foreground. 
Finished background zip of: mydata.txt 
Main program waited until background was done. 
Press any key to continue . . . 
</div>

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

</div>

您可能想查找下面的文章:

  • Python多线程实现同步的四种方式
  • Python多线程实现同步的四种方式
  • Python 多线程实例详解
  • Python 多线程实例详解
  • Python实现的多线程http压力测试代码
  • python实现多线程抓取知乎用户
  • python 线程的暂停, 恢复, 退出详解及实例
  • 深入理解 Python 中的多线程 新手必看
  • python 简单的多线程链接实现代码
  • python 简单的多线程链接实现代码

相关文章

  • Python加pyGame实现的简单拼图游戏实例
  • 树莓派中python获取GY-85九轴模块信息示例
  • Python中使用MELIAE分析程序内存占用实例
  • 用python读写excel的方法
  • Windows下用py2exe将Python程序打包成exe程序的教程
  • Python中将字典转换为XML以及相关的命名空间解析
  • Win7下搭建python开发环境图文教程(安装Python、pip、解释器)
  • Python 时间处理datetime实例
  • 用python + openpyxl处理excel2007文档思路以及心得
  • 跟老齐学Python之玩转字符串(2)

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python与Java间Socket通信实例代码
    • 通过实例浅析Python对比C语言的编程思想差异
    • python定时采集摄像头图像上传ftp服务器功能实现
    • python中redis的安装和使用
    • 使用Python编写简单的画图板程序的示例教程
    • python求解水仙花数的方法
    • Python类的动态修改的实例方法
    • Python实现保证只能运行一个脚本实例
    • 利用一个简单的例子窥探CPython内核的运行机制
    • Python实现随机生成任意数量车牌号

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有