Skip to content

Commit

Permalink
Use httpx client without keep alive connections
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Oct 7, 2024
1 parent 4f81eeb commit f016e01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 0 additions & 2 deletions R/remotebmi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ client.get_value('Q', dest=np.array([.1]))
array([0.0044])
client.get_var_nbytes('Q')
'mm/h'
# TODO get_var_nbytes should return int not str
# this breaks reserve_values() aswell
dest = reserve_values(client, 'Q')
r = client.get_value('Q', dest)
r
Expand Down
9 changes: 6 additions & 3 deletions python/remotebmi/client/client.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import numpy as np
from bmipy import Bmi
from httpx import Client
from httpx import Client, Limits
from numpy import ndarray


class RemoteBmiClient(Bmi):
def __init__(self, base_url):
self.client = Client(base_url=base_url)
def __init__(self, base_url, max_keepalive_connections=0):
# In some Python environments the reusing connection causes `illegal status line: bytesarray(b'14')` error
# So we need to disable keepalive connections to be more reliable, but less efficient
limits = Limits(max_keepalive_connections=max_keepalive_connections)
self.client = Client(base_url=base_url, limits=limits)

def __del__(self):
self.client.close()
Expand Down

0 comments on commit f016e01

Please sign in to comment.