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
评论列表
文章目录