langfuse._task_manager.media_upload_consumer

 1import logging
 2import threading
 3
 4from .media_manager import MediaManager
 5
 6
 7class MediaUploadConsumer(threading.Thread):
 8    _log = logging.getLogger(__name__)
 9    _identifier: int
10    _max_retries: int
11    _media_manager: MediaManager
12
13    def __init__(
14        self,
15        *,
16        identifier: int,
17        media_manager: MediaManager,
18    ):
19        """Create a consumer thread."""
20        super().__init__()
21        # Make consumer a daemon thread so that it doesn't block program exit
22        self.daemon = True
23        # It's important to set running in the constructor: if we are asked to
24        # pause immediately after construction, we might set running to True in
25        # run() *after* we set it to False in pause... and keep running
26        # forever.
27        self.running = True
28        self._identifier = identifier
29        self._media_manager = media_manager
30
31    def run(self):
32        """Run the media upload consumer."""
33        self._log.debug("consumer is running...")
34        while self.running:
35            self._media_manager.process_next_media_upload()
36
37    def pause(self):
38        """Pause the media upload consumer."""
39        self.running = False
class MediaUploadConsumer(threading.Thread):
 8class MediaUploadConsumer(threading.Thread):
 9    _log = logging.getLogger(__name__)
10    _identifier: int
11    _max_retries: int
12    _media_manager: MediaManager
13
14    def __init__(
15        self,
16        *,
17        identifier: int,
18        media_manager: MediaManager,
19    ):
20        """Create a consumer thread."""
21        super().__init__()
22        # Make consumer a daemon thread so that it doesn't block program exit
23        self.daemon = True
24        # It's important to set running in the constructor: if we are asked to
25        # pause immediately after construction, we might set running to True in
26        # run() *after* we set it to False in pause... and keep running
27        # forever.
28        self.running = True
29        self._identifier = identifier
30        self._media_manager = media_manager
31
32    def run(self):
33        """Run the media upload consumer."""
34        self._log.debug("consumer is running...")
35        while self.running:
36            self._media_manager.process_next_media_upload()
37
38    def pause(self):
39        """Pause the media upload consumer."""
40        self.running = False

A class that represents a thread of control.

This class can be safely subclassed in a limited fashion. There are two ways to specify the activity: by passing a callable object to the constructor, or by overriding the run() method in a subclass.

MediaUploadConsumer( *, identifier: int, media_manager: langfuse._task_manager.media_manager.MediaManager)
14    def __init__(
15        self,
16        *,
17        identifier: int,
18        media_manager: MediaManager,
19    ):
20        """Create a consumer thread."""
21        super().__init__()
22        # Make consumer a daemon thread so that it doesn't block program exit
23        self.daemon = True
24        # It's important to set running in the constructor: if we are asked to
25        # pause immediately after construction, we might set running to True in
26        # run() *after* we set it to False in pause... and keep running
27        # forever.
28        self.running = True
29        self._identifier = identifier
30        self._media_manager = media_manager

Create a consumer thread.

daemon
1200    @property
1201    def daemon(self):
1202        """A boolean value indicating whether this thread is a daemon thread.
1203
1204        This must be set before start() is called, otherwise RuntimeError is
1205        raised. Its initial value is inherited from the creating thread; the
1206        main thread is not a daemon thread and therefore all threads created in
1207        the main thread default to daemon = False.
1208
1209        The entire Python program exits when only daemon threads are left.
1210
1211        """
1212        assert self._initialized, "Thread.__init__() not called"
1213        return self._daemonic

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

running
def run(self):
32    def run(self):
33        """Run the media upload consumer."""
34        self._log.debug("consumer is running...")
35        while self.running:
36            self._media_manager.process_next_media_upload()

Run the media upload consumer.

def pause(self):
38    def pause(self):
39        """Pause the media upload consumer."""
40        self.running = False

Pause the media upload consumer.

Inherited Members
threading.Thread
start
join
name
ident
is_alive
isDaemon
setDaemon
getName
setName
native_id