风-fmgao

导航

上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 45 下一页

2018年6月19日

协程小示例

摘要: #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time : 2018/6/19 15:03# @File : 协程.py# 协程:单线程下实现并发import timedef producer(): g = consumer() next(g) for i 阅读全文

posted @ 2018-06-19 16:27 风-fmgao 阅读(117) 评论(0) 推荐(0) 编辑

协程基础

摘要: 一 引子 一:其中第二种情况并不能提升效率, 只是为了让cpu能够雨露均沾,实现看起来所有任务都被“同时”执行的效果,如果多个任务都是纯计算的,这种切换反而会降低效率。为此我们可以基于yield来验证。yield本身就是一种在单线程下可以保存任务运行状态的方法,我们来简单复习一下 单纯地切换反而会降 阅读全文

posted @ 2018-06-19 16:26 风-fmgao 阅读(126) 评论(0) 推荐(0) 编辑

异步调用回调实例

摘要: #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time : 2018/6/19 14:30# @File : 进程池线程池练习.pyfrom concurrent.futures import ThreadPoolExecutorimport request 阅读全文

posted @ 2018-06-19 14:54 风-fmgao 阅读(91) 评论(0) 推荐(0) 编辑

异步调用与回调机制

摘要: #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time : 2018/6/19 14:05# @File : 异步调用与回调机智.py """ 同步调用和阻塞不一样: 同步调用不管是io型程序还是计算型程序,执行一个程序之后就是等待, 阻塞是io型特有的,因 阅读全文

posted @ 2018-06-19 14:29 风-fmgao 阅读(87) 评论(0) 推荐(0) 编辑

初探进程池线程池

摘要: #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time : 2018/6/19 10:20# @File : 进程池线程池.py# ProcessPoolExecutor和ThreadPoolExecutor接口一样# 计算密集型--进程 ,io密集型--线 阅读全文

posted @ 2018-06-19 11:06 风-fmgao 阅读(80) 评论(0) 推荐(0) 编辑

多线程并发简单版

摘要: server #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time : 2018/6/19 9:33# @File : server1.py# from socket import *# from threading import Thread### de 阅读全文

posted @ 2018-06-19 09:53 风-fmgao 阅读(84) 评论(0) 推荐(0) 编辑

队列queue

摘要: #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time : 2018/6/19 9:11# @File : 线程queue.pyimport queue# q = queue.Queue(3) # 先进先出- 队列## q.put('first')# q.p 阅读全文

posted @ 2018-06-19 09:31 风-fmgao 阅读(106) 评论(0) 推荐(0) 编辑

验证码-定时器版

摘要: #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time : 2018/6/19 8:50# @File : 定时器.py# 简单定时器# from threading import Timer## def task(name):# print('hello 阅读全文

posted @ 2018-06-19 09:10 风-fmgao 阅读(124) 评论(0) 推荐(0) 编辑

2018年6月18日

event事件

摘要: #!/usr/bin/env python # encoding: utf-8 # Date: 2018/6/18# from threading import Thread,Event# import time# event = Event()# # event.wait()# # event.s 阅读全文

posted @ 2018-06-18 23:39 风-fmgao 阅读(97) 评论(0) 推荐(0) 编辑

信号量

摘要: #!/usr/bin/env python # encoding: utf-8 # Date: 2018/6/18from threading import Thread,Semaphore,currentThreadimport timeimport randomsm = Semaphore(3) 阅读全文

posted @ 2018-06-18 23:17 风-fmgao 阅读(86) 评论(0) 推荐(0) 编辑

上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 45 下一页