Could you add the with-as syntax #312

Open
opened 2026-02-15 16:29:50 -05:00 by yindo · 0 comments
Owner

Originally created by @Freakwill on GitHub (Jan 14, 2026).

It is better to add with-syntax

with ollama.Client() as c: pass
...
Traceback (most recent call last):
File "", line 1, in
TypeError: 'Client' object does not support the context manager protocol

My approach is (for MacOS)

    def __enter__(self, *args, **kwargs):
        import sh
        sh.brew.services.start.ollama()
        return self

    def __exit__(self, *args, **kwargs):
        import sh
        sh.brew.services.stop.ollama()
Originally created by @Freakwill on GitHub (Jan 14, 2026). It is better to add with-syntax >>> with ollama.Client() as c: pass ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'Client' object does not support the context manager protocol My approach is (for MacOS) ``` def __enter__(self, *args, **kwargs): import sh sh.brew.services.start.ollama() return self def __exit__(self, *args, **kwargs): import sh sh.brew.services.stop.ollama() ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#312