V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  gdsagdada  ›  全部回复第 9 页 / 共 16 页
回复总数  314
1  2  3  4  5  6  7  8  9  10 ... 16  
2017-01-19 11:52:15 +08:00
回复了 thekoc 创建的主题 Python sqlite3 多线程高并发的访问如何处理?
楼主改 py2 了记得也贴下
2017-01-19 11:50:02 +08:00
回复了 thekoc 创建的主题 Python sqlite3 多线程高并发的访问如何处理?
# coding:utf-8
import sqlite3
import queue, os


def singleton(cls):
instances = {}

def _singleton(*args, **kw):
if cls not in instances:
instances[cls] = cls(*args, **kw)
return instances[cls]

return _singleton


@singleton
class SQLiteUtil(object):
__queue_conn = queue.Queue(maxsize=1)
__path = None

def __init__(self, path):
self.__path = path
print('path:', self.__path)
self.__create_conn()

def __create_conn(self):
conn = sqlite3.connect(self.__path, check_same_thread=False)
self.__queue_conn.put(conn)

def __close(self, cursor, conn):
if cursor is not None:
cursor.close()
if conn is not None:
cursor.close()
self.__create_conn()

def execute_query(self, sql, params):
conn = self.__queue_conn.get()
cursor = conn.cursor()
value = None
try:
records = None
if not params is None:
records = cursor.execute(sql, params).fetchall()
else:
records = cursor.execute(sql).fetchall()
field = [i[0] for i in cursor.description]
value = [dict(zip(field, i)) for i in records]
finally:
self.__close(cursor, conn)
return value

def executescript(self, sql):
conn = self.__queue_conn.get()
cursor = conn.cursor()
try:
cursor.executescript(sql)
conn.commit()
except Exception as e:
conn.rollback()
raise
finally:
self.__close(cursor, conn)

def execute_update(self, sql, params):
return self.execute_update_many([sql], [params])

def execute_update_many(self, sql_list, params_list):
conn = self.__queue_conn.get()
cursor = conn.cursor()
count = 0
try:
for index in range(len(sql_list)):
sql = sql_list[index]
params = params_list[index]
if not params is None:
count += cursor.execute(sql, params).rowcount
else:
count += cursor.execute(sql).rowcount
conn.commit()
except Exception as e:
conn.rollback()
raise
finally:
self.__close(cursor, conn)
return count


'''
example:

one = SQLiteUtil('xxx.sqlite')

rst = one.execute_query('select * from website', None)
for line in rst:
print(line.get('id'), line.get('url'), line.get('content'))


print(one.execute_update('update website set content = \'2222222\' where id = ?', ('1',)))
print(one.execute_update('update website set content = \'2222222\' where id = \'1\'', None))


print('update many')
count = one.execute_update_many(
[
'update website set content = \'一\' where id = \'1\'',
'update website set content = \'二\' where id = \'2\'',
'update website set content = 1 where id = \'3\''
],
[None, None, None]
)
print('count:', count)
'''

python3 的 用 py2 自己改改,可抗千万级并发[v2ex 滑稽专属表情]
2017-01-19 11:31:54 +08:00
回复了 dettac 创建的主题 Wikipedia 如何下载特定的 wikipedia 数据?
https://www.zhihu.com/question/19803440
问前先搜索,爬虫不现实
2017-01-19 11:26:34 +08:00
回复了 xcatliu 创建的主题 分享创造 随手撸了个测试屏幕坏点的网页
去掉所有文字,单击换色,方可解决所有设备
2017-01-18 18:11:45 +08:00
回复了 makeitall 创建的主题 程序员 imagemagick 水印 gif 时候遇到的问题(内详有图)
可能因为 gif 帧大小不一样
2017-01-18 18:07:44 +08:00
回复了 cheetah 创建的主题 问与答 有什么服务可以让我方便的给网站加一个捐助页面吗?
楼主要不贴我的微信二维码,支付宝也行,比特币 paypal 也还行
2017-01-18 18:06:20 +08:00
回复了 SophiaZhang 创建的主题 分享创造 两人一起开发的独立项目-免费在线 APP 原型工具
@gaobh 企业用的软件不建议小白话,因为需求多种多样,功能不怕多就怕没有,参见 office 系列,功能一多很考验设计能力,要不然以后 bug 一大堆
2017-01-18 17:56:59 +08:00
回复了 SophiaZhang 创建的主题 分享创造 两人一起开发的独立项目-免费在线 APP 原型工具
还不错,套个 https://github.com/electron/electron 搞个离线程序,加登录
2017-01-18 17:53:08 +08:00
回复了 chenyu0532 创建的主题 UNITY unity 水平等级划分
帮你顶一个,行内人柿来说说
2017-01-16 22:46:53 +08:00
回复了 gdsagdada 创建的主题 Apple 扯扯我这几年 macbook pro 用的最爽的鼠标
@oooovvssdsx 我是重度鼠标点按用户, macbook 自带触版手磨的不能自理,划来划去太费劲了
2017-01-16 14:08:31 +08:00
回复了 hnair 创建的主题 酷工作 [海南航空] 诚聘高级 JavaEE 工程师
@163.com 不专业,说不定是坑
2017-01-16 12:26:22 +08:00
回复了 xiaoyu9527 创建的主题 问与答 现在百度网盘 必须冲超级会员了么?
以前百度网盘出 bug ,我不是会员 100M 带宽,居然能 7 、 8KB 的下载,老感动了!
2017-01-16 12:25:21 +08:00
回复了 xiaoyu9527 创建的主题 问与答 现在百度网盘 必须冲超级会员了么?
百度网盘不是非会员禁止下载吗?[滑稽]
2017-01-14 20:02:29 +08:00
回复了 bianhua 创建的主题 寻人 @18616942091 兄弟,你为什么要用我的手机号注册 V2EX?
2017-01-14 20:00:29 +08:00
回复了 bianhua 创建的主题 寻人 @18616942091 兄弟,你为什么要用我的手机号注册 V2EX?
2017-01-14 19:59:45 +08:00
回复了 bianhua 创建的主题 寻人 @18616942091 兄弟,你为什么要用我的手机号注册 V2EX?
2017-01-14 15:04:36 +08:00
回复了 gdsagdada 创建的主题 Apple 扯扯我这几年 macbook pro 用的最爽的鼠标
滚轮对 macbook 支持最好的鼠标我用过的:
M558 、 Microsoft Designer 、 Microsoft Designer 2014 ,仅仅是中间的滚轮

我的鼠标设置,卸载厂商鼠标驱动:
系统-偏好设置-鼠标-滚动方向:自然-跟踪速度 5 档-滚动速度 4 档
2017-01-13 16:27:42 +08:00
回复了 gyfwhu 创建的主题 职场话题 应届生 offer 求指点
微众银行<<<<<<<<<<<<<<<<<<<招行信用卡中心
1  2  3  4  5  6  7  8  9  10 ... 16  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2924 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 31ms · UTC 14:48 · PVG 22:48 · LAX 07:48 · JFK 10:48
Developed with CodeLauncher
♥ Do have faith in what you're doing.