__init__.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:battray 作者: Carpetsmoker 项目源码 文件源码
def set_proctitle(title):
    try:
        # This is probably the best way to do this, but I don't want to force an
        # external dependency on this C module...
        import setproctitle
        setproctitle.setproctitle(title)
    except ImportError:
        import ctypes, ctypes.util

        libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c'))
        title_bytes = title.encode(sys.getdefaultencoding(), 'replace')
        buf = ctypes.create_string_buffer(title_bytes)

        # BSD, maybe also OSX?
        try:
            libc.setproctitle(ctypes.create_string_buffer(b"-%s"), buf)
            return
        except AttributeError:
            pass

        # Linux
        try:
            libc.prctl(15, buf, 0, 0, 0)
            return
        except AttributeError:
            pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号