Skip to content

Commit

Permalink
Merge pull request #1200 from OCR-D/mets-server-session-per-method
Browse files Browse the repository at this point in the history
METS server: don't cache the session to avoid broken connections
  • Loading branch information
kba committed Apr 16, 2024
2 parents 7fce1c4 + b0c1e91 commit 83efd8f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ocrd/mets_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import socket
import atexit

from fastapi import FastAPI, Request, Form, Response
from fastapi import FastAPI, Request, Form, Response, requests
from fastapi.responses import JSONResponse
from requests import Session as requests_session
from requests.exceptions import ConnectionError
Expand Down Expand Up @@ -99,10 +99,13 @@ class ClientSideOcrdMets():
"""

def __init__(self, url):
protocol = 'tcp' if url.startswith('http://') else 'uds'
self.protocol = 'tcp' if url.startswith('http://') else 'uds'
self.log = getLogger(f'ocrd.mets_client[{url}]')
self.url = url if protocol == 'tcp' else f'http+unix://{url.replace("/", "%2F")}'
self.session = requests_session() if protocol == 'tcp' else requests_unixsocket_session()
self.url = url if self.protocol == 'tcp' else f'http+unix://{url.replace("/", "%2F")}'

@property
def session(self) -> Union[requests_session, requests_unixsocket_session]:
return requests_session() if self.protocol == 'tcp' else requests_unixsocket_session()

def __getattr__(self, name):
raise NotImplementedError(f"ClientSideOcrdMets has no access to '{name}' - try without METS server")
Expand Down

0 comments on commit 83efd8f

Please sign in to comment.