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
leeside
V2EX  ›  Python

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

  •  
  •   leeside · 2 天前 · 969 次点击

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

    4 条回复    2024-07-04 13:31:26 +08:00
    linquan
        1
    linquan  
       2 天前   ❤️ 1
    你搜下 python 键盘信号处理,加一个 ctrl+C 终止程序的函数试试
    clemente
        2
    clemente  
       2 天前   ❤️ 1
    pybind 可以啊
    exiledkingcc
        3
    exiledkingcc  
       2 天前   ❤️ 1
    本来就不能关闭啊,ctrl+C 的信号只会给到主线程,其它线程不会自动结束。
    解决方法:C++用 jthread 或者把 thread 中循环加判断,自己退出;或者,不用 join ,用 detach 。
    leeside
        4
    leeside  
    OP
       1 天前
    @linquan
    @clemente
    @exiledkingcc 感谢各位,这就去试试。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4922 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 08:54 · PVG 16:54 · LAX 01:54 · JFK 04:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.