Skip to content

Instantly share code, notes, and snippets.

@gaoconghui
gaoconghui / downloader.py
Last active February 13, 2022 12:15
大文件多线程下载
# -*- coding: utf-8 -*-
import os
import threading
import requests
import tqdm
class Downloader(object):
def __init__(self, url, name="notitle", worker_num=8, resume=True):
@gaoconghui
gaoconghui / redis_lock.py
Last active May 18, 2020 04:26
基于redis的悲观锁
# coding: utf-8
"""
redis 分布式悲观锁,需要解决以下几个问题
1、A获取锁后崩溃,需要能将锁释放
2、A获取锁后处理时间过长,导致锁过期,被B获取,A处理完后错误的将B锁释放
redis.Redis()会有些问题,连接最好使用redis.StrictRedis()
"""
import math