Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

METS server: don't cache the session to avoid broken connections #1200

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading