Skip to content

Commit

Permalink
terminate context
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketmaurya committed Jan 9, 2025
1 parent a4fc585 commit 105fa5a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/litserve/loops/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def run(
"""

zmq_ctx: Optional[zmq.Context] = None
socket: Optional[zmq.Socket] = None

def pre_setup(self, lit_api: LitAPI, spec: Optional[LitSpec]):
Expand Down Expand Up @@ -265,6 +266,7 @@ def put_error_response(
def __del__(self):
if self.socket:
self.socket.close()
self.zmq_ctx.term()


class DefaultLoop(LitLoop):
Expand Down
3 changes: 2 additions & 1 deletion src/litserve/loops/loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def inference_worker(
socket = ctx.socket(zmq.PUB)
logger.debug(f"Inference worker binding to port {zmq_port}")
socket.bind(f"tcp://*:{zmq_port}")
loop.zmq_context = ctx

loop(
lit_api,
Expand All @@ -101,4 +102,4 @@ def inference_worker(
)
if use_zmq:
socket.close()
ctx.destroy()
loop.zmq_context.term()

0 comments on commit 105fa5a

Please sign in to comment.