• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






Apollo

 
 

Powered by 博客园
| | 新随笔 | | | 管理

随笔分类 -  并发编程

1 2 下一页

 
python并发编程知识点总结
摘要:1.到底什么是线程?什么是进程? Python自己没有这玩意,Python中调用的操作系统的线程和进程. 2.Python多线程情况下: 计算密集型操作:效率低,Python内置的一个全局解释器锁,锁的作用就是保证同一时刻一个进程中只有一个线程可以被cpu调度,多线程无法利用多核优势,可以通过多进程 阅读全文
posted @ 2019-02-04 11:36 阿波罗Apollo 阅读(362) 评论(0) 推荐(0)
协程+IO切换实现并发
摘要:``` from gevent import monkey # 以后代码中遇到IO都会自动执行greenlet的switch进行切换 monkey.patch_all() import requests import gevent def get_page1(url): ret = requests.get(url) print(url,ret.content) def g... 阅读全文
posted @ 2019-02-04 11:31 阿波罗Apollo 阅读(258) 评论(0) 推荐(0)
python单线程解决并发
摘要:1.单线程解决并发 方式一 方式二 阅读全文
posted @ 2019-02-04 11:30 阿波罗Apollo 阅读(257) 评论(0) 推荐(0)
不改变代码情况下,让列表增加方法
摘要:原代码 修改后代码 阅读全文
posted @ 2019-02-04 11:11 阿波罗Apollo 阅读(196) 评论(0) 推荐(0)
python基于yield实现协程
摘要:``` def f1(): print(11) yield print(22) yield print(33) def f2(): print(55) yield print(66) yield print(77) v1 = f1() v2 = f2() next(v1) # v1.send(None) next... 阅读全文
posted @ 2019-02-04 11:03 阿波罗Apollo 阅读(154) 评论(0) 推荐(0)
携程greenlet模块使用
摘要:``` import greenlet def f1(): print(11) gr2.switch() print(22) gr2.switch() def f2(): print(33) gr1.switch() print(44) # 协程 gr1 gr1 = greenlet.greenlet(f1) # 协程 gr2 g... 阅读全文
posted @ 2019-02-04 11:00 阿波罗Apollo 阅读(131) 评论(0) 推荐(0)
如何让socket编程非阻塞?
摘要:``` import socket # 创建socket client = socket.socket() # 将原来阻塞的位置变成非阻塞(报错) client.setblocking(False) # 百度创建连接: 阻塞 try: # 执行了但报错了 client.connect(('www.baidu.com',80)) except BlockingIOError as ... 阅读全文
posted @ 2019-02-04 10:33 阿波罗Apollo 阅读(350) 评论(0) 推荐(0)
分别用request和socket给百多发送请求
摘要:1.方式1 2.方式2 阅读全文
posted @ 2019-02-04 10:24 阿波罗Apollo 阅读(234) 评论(0) 推荐(0)
python线程池应用场景-爬虫
摘要:``` import requests from bs4 import BeautifulSoup from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor def task(url): print(url) r1 = requests.get( url=url, ... 阅读全文
posted @ 2019-02-04 10:14 阿波罗Apollo 阅读(375) 评论(0) 推荐(0)
python线程池/进程池创建
摘要:进程池 线程池 阅读全文
posted @ 2019-02-04 10:10 阿波罗Apollo 阅读(288) 评论(0) 推荐(0)
python进程锁
摘要:和线程锁一样,对照线程锁学习即可 阅读全文
posted @ 2019-02-04 10:05 阿波罗Apollo 阅读(176) 评论(0) 推荐(0)
进程间实现数据共享的三种方式
摘要:1.Queue: linux: windows: 2.Manager:( ) Linux: windows: 3.其他电脑 阅读全文
posted @ 2019-02-04 10:04 阿波罗Apollo 阅读(1984) 评论(0) 推荐(0)
python创建进程的两种方式
摘要:1.方式1 2.方式2 阅读全文
posted @ 2019-02-04 09:55 阿波罗Apollo 阅读(170) 评论(0) 推荐(0)
python线程间数据共享(示例演示)
摘要:``` import threading data_list = [] def task(arg): data_list.append(arg) print(data_list) def run(): for i in range(10): p = threading.Thread(target=t 阅读全文
posted @ 2019-02-04 09:47 阿波罗Apollo 阅读(355) 评论(0) 推荐(0)
python进程间数据不共享(示例演示)
摘要:``` import multiprocessing data_list = [] def task(arg): data_list.append(arg) print(data_list) def run(): for i in range(10): p = multiprocessing.Process(target=task, args=(i... 阅读全文
posted @ 2019-02-04 09:46 阿波罗Apollo 阅读(125) 评论(0) 推荐(0)
python生产者消费者模型
摘要:``` import time import queue import threading q = queue.Queue() # 线程安全 def producer(id): """生产者""" while True: time.sleep(2) q.put('包子') print('厨师%s 生产了一个包子' % id) ... 阅读全文
posted @ 2019-02-04 09:41 阿波罗Apollo 阅读(166) 评论(0) 推荐(0)
python创建一个线程和一个线程池
摘要:创建一个线程 1.示例代码 创建一个线程池 1.示例代码 2.示例代码 阅读全文
posted @ 2019-02-03 20:41 阿波罗Apollo 阅读(358) 评论(0) 推荐(0)
多线程threading.local的作用及原理?
摘要:1.示例代码 2.原理 3.拓展 总结: 1.obj.x 调用方法__getattr__ 2.obj.x = 6 调用方法__setattr__ 4.作用 内部自动为每个线程维护一个空间(字典),用于当前存取属于自己的值。保证线程之间的数据隔离。 { 线程ID: {...} 线程ID: {...} 阅读全文
posted @ 2019-02-03 20:35 阿波罗Apollo 阅读(318) 评论(0) 推荐(0)
python多线程锁lock/Rlock/BoundedSemaphore/Condition/Event
摘要:''' 期望结果 加锁情况: 当前线程 0 修改后n的值为: 0 当前线程 1 修改后n的值为: 1 当前线程 2 修改后n的值为: 2 当前线程 3 修改后n的值为: 3 当前线程 4 修改后n的值为: 4 ''' ''' 不期望结果 没加锁情况 当前线程 0 修改后n的值为: 4 当前线程 1 阅读全文
posted @ 2019-02-03 20:11 阿波罗Apollo 阅读(214) 评论(0) 推荐(0)
python多线程的两种写法
摘要:1.一般多线程 2.面向对象版多线程 阅读全文
posted @ 2019-02-03 19:50 阿波罗Apollo 阅读(443) 评论(0) 推荐(0)
 

1 2 下一页