From dbaff524a558e147e5f8788ef5070ee598872c59 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Fri, 24 Apr 2020 17:18:41 +0100 Subject: [PATCH] Generate target string before applying request context --- labthings/core/tasks/thread.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/labthings/core/tasks/thread.py b/labthings/core/tasks/thread.py index 99646c9c..ee1d5487 100644 --- a/labthings/core/tasks/thread.py +++ b/labthings/core/tasks/thread.py @@ -33,6 +33,9 @@ def __init__(self, target, *args, **kwargs): self._args = args self._kwargs = kwargs + # Nice string representation of target function + self.target_string = f"{self._target}(args={self._args}, kwargs={self._kwargs})" + # copy_current_request_context allows threads to access flask current_app if has_request_context(): logging.debug(f"Copying request context to {self._target}") @@ -40,9 +43,6 @@ def __init__(self, target, *args, **kwargs): else: logging.debug("No request context to copy") - # Nice string representation of target function - self.target_string = f"{self._target}(args={self._args}, kwargs={self._kwargs})" - # Private state properties self._status: str = "idle" # Task status self._return_value = None # Return value