Skip to content

Commit ea58ed3

Browse files
committed
Refactored 'murfey.instrument_server.__init__' so that the Murfey update checker is run through to completion before the components needed to update the server are imported and initialised, thereby avoiding the files associated with the process from becoming locked
1 parent f95dd07 commit ea58ed3

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/murfey/instrument_server/__init__.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
1-
import argparse
21
import logging
32
from urllib.parse import urlparse
43

5-
import uvicorn
6-
from rich.logging import RichHandler
7-
8-
import murfey
9-
import murfey.client.update
10-
import murfey.client.websocket
11-
from murfey.client.customlogging import CustomHandler
12-
from murfey.util import LogFilter
134
from murfey.util.client import read_config
145

156
logger = logging.getLogger("murfey.instrument_server")
167

178

18-
def run():
9+
def check_for_updates():
10+
import murfey.client.update
11+
12+
murfey_url = urlparse(
13+
read_config().get("Murfey", "server", fallback=""), allow_fragments=False
14+
)
15+
try:
16+
murfey.client.update.check(murfey_url)
17+
except Exception as e:
18+
print(f"Murfey update check failed with {e}")
19+
20+
21+
def start_instrument_server():
22+
import argparse
23+
24+
import uvicorn
25+
from rich.logging import RichHandler
26+
27+
import murfey
28+
import murfey.client.websocket
29+
from murfey.client.customlogging import CustomHandler
30+
from murfey.util import LogFilter
31+
1932
parser = argparse.ArgumentParser(description="Start the Murfey server")
2033
parser.add_argument(
2134
"--host",
@@ -30,12 +43,6 @@ def run():
3043
)
3144
args = parser.parse_args()
3245

33-
murfey_url = urlparse(read_config()["Murfey"].get("server"), allow_fragments=False)
34-
try:
35-
murfey.client.update.check(murfey_url)
36-
except Exception as e:
37-
print(f"Murfey update check failed with {e}")
38-
3946
LogFilter.install()
4047

4148
rich_handler = RichHandler(enable_link_path=False)
@@ -45,7 +52,7 @@ def run():
4552
logging.getLogger("uvicorn").addHandler(rich_handler)
4653

4754
ws = murfey.client.websocket.WSApp(
48-
server=read_config()["Murfey"].get("server"),
55+
server=read_config().get("Murfey", "server", fallback=""),
4956
register_client=False,
5057
)
5158

@@ -71,3 +78,8 @@ def run():
7178
_running_server = uvicorn.Server(config=config)
7279
_running_server.run()
7380
logger.info("Instrument server shutting down")
81+
82+
83+
def run():
84+
check_for_updates()
85+
start_instrument_server()

0 commit comments

Comments
 (0)