V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
abersheeran
V2EX  ›  Python

基于 Python PEP249 的连接池

  •  
  •   abersheeran ·
    abersheeran · 2021-01-13 17:15:38 +08:00 · 2141 次点击
    这是一个创建于 1171 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://www.python.org/dev/peps/pep-0249/

    在用这个 https://pypi.org/project/phoenixdb/ 进行操作,但是发现如果全局共享同一个连接,用线程池执行代码的时候会报错。所以想问问有没有基于 Python PEP249 的线程安全的连接池可用?

    如果没有,恐怕我又得造轮子了……说实话,最近造轮子整的我有点累。

    4 条回复    2021-01-14 09:26:31 +08:00
    black11black
        1
    black11black  
       2021-01-13 17:53:30 +08:00
    不了解业务环境,不过“全局共享同连接”本身应该避免吧,即使实现线程安全,锁的开销也很大。最近造了 py 连 oracle 接口的异步封装,基本原则是保证单连接同一时间不会有两个线程在操作。
    ruanimal
        2
    ruanimal  
       2021-01-13 17:55:55 +08:00
    连接池应该都是线程安全的,但是从连接池取出的连接的不能线程共享的,而且就算能共享也没啥意义吧。
    frostming
        3
    frostming  
       2021-01-13 22:19:25 +08:00
    同意 1 楼,不要在线程中共享连接
    abersheeran
        4
    abersheeran  
    OP
       2021-01-14 09:26:31 +08:00
    https://www.v2ex.com/t/733767#reply10 我保持沉默,以示尊重。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2901 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:23 · PVG 19:23 · LAX 04:23 · JFK 07:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.