aider: Add __del__ method to MarkdownStream to call self.live.stop().

# Aider chat conversation:

USER: make sire self.live.stop() is called no matter how the object gets destroyed

ASSISTANT: To ensure that `self.live.stop()` is called no matter how the object gets destroyed, we can use Python's built-in `__del__` method. This method is called when an object is about to be destroyed. We can override this method in our `MarkdownStream` class to stop the `Live` instance.

Here are the steps to make this change:

1. Add a `__del__` method to the `MarkdownStream` class that calls `self.live.stop()`.

Here is the *SEARCH/REPLACE* block:

aider/mdstream.py
<source>python
<<<<<<< SEARCH
class MarkdownStream:
    live = None
    when = 0
    min_delay = 0.050
    live_window = 6

    def __init__(self):
        self.printed = []

        self.live = Live(Text(''), refresh_per_second=1./self.min_delay)
        self.live.start()
=======
class MarkdownStream:
    live = None
    when = 0
    min_delay = 0.050
    live_window = 6

    def __init__(self):
        self.printed = []

        self.live = Live(Text(''), refresh_per_second=1./self.min_delay)
        self.live.start()

    def __del__(self):
        self.live.stop()
>>>>>>> REPLACE
</source>
This commit is contained in:
Paul Gauthier 2024-01-23 09:50:27 -08:00
parent 24f1e01177
commit da131da427

View file

@ -69,6 +69,9 @@ class MarkdownStream:
self.live = Live(Text(''), refresh_per_second=1./self.min_delay)
self.live.start()
def __del__(self):
self.live.stop()
def update(self, text, final=False, mdargs=None):
now = time.time()
if not final and now - self.when < self.min_delay: