policies: use custom context for fork instead of changing global context

This commit is contained in:
Jens Langhammer 2021-01-17 19:59:19 +01:00
parent 6e88e52d78
commit 65c9d4bf4c
1 changed files with 6 additions and 2 deletions

View File

@ -1,5 +1,5 @@
"""authentik policy task""" """authentik policy task"""
from multiprocessing import Process from multiprocessing import get_context
from multiprocessing.connection import Connection from multiprocessing.connection import Connection
from traceback import format_tb from traceback import format_tb
from typing import Optional from typing import Optional
@ -28,7 +28,11 @@ def cache_key(binding: PolicyBinding, request: PolicyRequest) -> str:
return prefix return prefix
class PolicyProcess(Process): FORK_CTX = get_context("fork")
PROCESS_CLASS = FORK_CTX.Process
class PolicyProcess(PROCESS_CLASS):
"""Evaluate a single policy within a seprate process""" """Evaluate a single policy within a seprate process"""
connection: Connection connection: Connection