推荐学习书目
› 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
leeside
0.01D
V2EX  ›  Python

Python 调用 cpp 动态库, 使用了 cpp 内的 join 函数

  •  
  •   leeside · Jul 3, 2024 · 4875 views
    This topic created in 821 days ago, the information mentioned may be changed or developed.

    1.c++这边的自己的库有一个接口是包装的 thread 的 join 函数 2.python 的包是通过 swig 包装的 c++库,swig 做的也是使用 cpython 在基础上生成的包装类 3.跑起来没啥问题,使用 ctrl c 不能直接关闭是为什么呢,是因为信号不能正确的传递吗 4.搜索了一圈没查到相关的资料,是我搜的不对吗

    4 replies  •  2024-07-04 13:31:26 +08:00
    linquan
        1
    linquan  
       Jul 3, 2024   ❤️ 1
    你搜下 python 键盘信号处理,加一个 ctrl+C 终止程序的函数试试
    clemente
        2
    clemente  
       Jul 3, 2024   ❤️ 1
    pybind 可以啊
    exiledkingcc
        3
    exiledkingcc  
       Jul 3, 2024   ❤️ 1
    本来就不能关闭啊,ctrl+C 的信号只会给到主线程,其它线程不会自动结束。
    解决方法:C++用 jthread 或者把 thread 中循环加判断,自己退出;或者,不用 join ,用 detach 。
    leeside
        4
    leeside  
    OP
       Jul 4, 2024
    @linquan
    @clemente
    @exiledkingcc 感谢各位,这就去试试。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2515 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:09 · PVG 21:09 · LAX 06:09 · JFK 09:09
    ♥ Do have faith in what you're doing.