Improve process naming (only on Linux).
This commit is contained in:
parent
058bc9f912
commit
f0701b32f6
17
cista/app.py
17
cista/app.py
|
@ -8,6 +8,8 @@ from pathlib import Path, PurePath, PurePosixPath
|
||||||
from stat import S_IFDIR, S_IFREG
|
from stat import S_IFDIR, S_IFREG
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
from wsgiref.handlers import format_date_time
|
from wsgiref.handlers import format_date_time
|
||||||
|
import multiprocessing
|
||||||
|
import sys
|
||||||
|
|
||||||
import brotli
|
import brotli
|
||||||
import sanic.helpers
|
import sanic.helpers
|
||||||
|
@ -31,9 +33,24 @@ app.blueprint(bp)
|
||||||
app.exception(Exception)(handle_sanic_exception)
|
app.exception(Exception)(handle_sanic_exception)
|
||||||
|
|
||||||
|
|
||||||
|
def procname(name):
|
||||||
|
if sys.platform == "linux":
|
||||||
|
from ctypes import cdll, byref, create_string_buffer
|
||||||
|
|
||||||
|
newname = name.encode()
|
||||||
|
libc = cdll.LoadLibrary("libc.so.6")
|
||||||
|
buff = create_string_buffer(len(newname) + 1)
|
||||||
|
buff.value = newname
|
||||||
|
libc.prctl(15, byref(buff), 0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
procname("cista-main")
|
||||||
|
|
||||||
|
|
||||||
@app.before_server_start
|
@app.before_server_start
|
||||||
async def main_start(app, loop):
|
async def main_start(app, loop):
|
||||||
config.load_config()
|
config.load_config()
|
||||||
|
procname(f"cista {config.config.path.name}")
|
||||||
N = max(2, min(8, cpu_count()))
|
N = max(2, min(8, cpu_count()))
|
||||||
app.ctx.threadexec = ThreadPoolExecutor(
|
app.ctx.threadexec = ThreadPoolExecutor(
|
||||||
max_workers=N, thread_name_prefix="cista-ioworker"
|
max_workers=N, thread_name_prefix="cista-ioworker"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user