会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
下路派出所
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
5
6
7
8
9
···
27
下一页
2019年7月11日
Focal Loss tensorflow 实现
摘要: def focal_loss(pred, y, alpha=0.25, gamma=2): r"""Compute focal loss for predictions. Multi-labels Focal loss formula: FL = -alpha * (z-p)^gamma * log(p) -(1-a...
阅读全文
posted @ 2019-07-11 10:43 下路派出所
阅读(3381)
评论(0)
推荐(0)
2019年7月8日
Python 多进程池
摘要: def get_html(n): time.sleep(n) print("sub_progress success") return n # 多进程池 pool = multiprocessing.Pool(multiprocessing.cpu_count()) result = pool.apply_async(get_html, args=(3,)) # 类...
阅读全文
posted @ 2019-07-08 22:37 下路派出所
阅读(323)
评论(0)
推荐(0)
python 多进程、多线程和协程对比
摘要: 1. 对于耗费CPU的操作来说,多进程优于多线程 2. 对于耗费IO操作来说,多线程优于多进程 3. 多进程切换代价大于多线程 4. 协程适用于:密集网络IO,适合网络IO
阅读全文
posted @ 2019-07-08 22:15 下路派出所
阅读(368)
评论(0)
推荐(0)
2019年7月7日
python threading Future源码解析
摘要: 1. Future内部还是用了condition这个锁 2. Cancel 2. result 3. set_result
阅读全文
posted @ 2019-07-07 21:54 下路派出所
阅读(515)
评论(0)
推荐(0)
python threading ThreadPoolExecutor源码解析
摘要: future: 未来对象,或task的返回容器 1. 当submit后: 2. _adjust_thread_count: 3. _worker: 4. WorkItem
阅读全文
posted @ 2019-07-07 21:33 下路派出所
阅读(857)
评论(0)
推荐(0)
python threading ThreadPoolExecutor
摘要: 获取成功的task返回 方法一: 方法二: wait,wait第几个任务执行完了以后才执行主线程,不然的话主线程会一直阻塞
阅读全文
posted @ 2019-07-07 20:39 下路派出所
阅读(856)
评论(1)
推荐(0)
python threading Semaphore
摘要: #Semaphore 是用于控制进入数量的锁,控制同时进行的线程,内部是基于Condition来进行实现的 #文件, 读、写, 写一般只是用于一个线程写,读可以允许有多个 #做爬虫 import threading import time class HtmlSpider(threading.Thread): def __init__(self, url, sem): ...
阅读全文
posted @ 2019-07-07 19:59 下路派出所
阅读(1843)
评论(1)
推荐(0)
python Condition
摘要: condition有两层锁: 1. 一把底层锁会在线程调用了wait方法的时候释放(是先创建一把锁(这就是第二把锁),然后再release),底层还是Lock或者RLock, 2.第二把锁会在每次调用wait的时候创建一把新的,并放入到cond的等待队列中(采用的是dqueue),一直acquire
阅读全文
posted @ 2019-07-07 12:36 下路派出所
阅读(722)
评论(1)
推荐(0)
2019年7月6日
python Lock、RLock
摘要: Lock: 只能acquire一次,下一次acquire必须release后才能,不然会造成死锁 RLock: 在同一个线程里面,可以连续调用多次acquire, 一定要注意acquire的次数要和release的次数相等
阅读全文
posted @ 2019-07-06 11:44 下路派出所
阅读(3359)
评论(1)
推荐(0)
python 使用队列实现线程同步
摘要: #通过queue的方式进行线程间同步,Queue在底层通过实现了dqueue(双生队列,在字节码时实现了线程安全)实现了线程安全 from queue import Queue import time import threading def get_detail_html(queue): #爬取文章详情页 while True: url = queue....
阅读全文
posted @ 2019-07-06 11:21 下路派出所
阅读(1118)
评论(1)
推荐(0)
上一页
1
2
3
4
5
6
7
8
9
···
27
下一页
公告