From f015b8e7a1829023c539a8c56dfac8950ae321be Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Wed, 10 Dec 2025 18:12:08 +0100 Subject: [PATCH] avoid raise condition with parallel running profilers --- radicale/app/__init__.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/radicale/app/__init__.py b/radicale/app/__init__.py index fc7e1981..df02d14b 100644 --- a/radicale/app/__init__.py +++ b/radicale/app/__init__.py @@ -224,6 +224,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead, unsafe_path = environ.get("PATH_INFO", "") https = environ.get("HTTPS", "") profiler = None + profiler_active = False xml_request = None context = AuthContext() @@ -471,9 +472,19 @@ class Application(ApplicationPartDelete, ApplicationPartHead, # Profiling if self._profiling_per_request: profiler = cProfile.Profile() - profiler.enable() + try: + profiler.enable() + except ValueError: + profiler_active = False + else: + profiler_active = True elif self._profiling_per_request_method: - self.profiler_per_request_method[request_method].enable() + try: + self.profiler_per_request_method[request_method].enable() + except ValueError: + profiler_active = False + else: + profiler_active = True status, headers, answer, xml_request = function( environ, base_prefix, path, user, remote_host, remote_useragent) @@ -481,9 +492,11 @@ class Application(ApplicationPartDelete, ApplicationPartHead, # Profiling if self._profiling_per_request: if profiler is not None: - profiler.disable() + if profiler_active is True: + profiler.disable() elif self._profiling_per_request_method: - self.profiler_per_request_method[request_method].disable() + if profiler_active is True: + self.profiler_per_request_method[request_method].disable() if (status, headers, answer, xml_request) == httputils.NOT_ALLOWED: logger.info("Access to %r denied for %s", path,