Skip to content

Commit

Permalink
MXCUBEApplication and Server are static clases and should not be inst…
Browse files Browse the repository at this point in the history
…anciated
  • Loading branch information
marcus-oscarsson committed Sep 20, 2023
1 parent 71ca996 commit 6ed6f7c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 25 deletions.
20 changes: 6 additions & 14 deletions mxcube3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


from gevent import monkey

monkey.patch_all(thread=False)

from mxcube3.server import Server
Expand All @@ -18,9 +19,6 @@
sys.modules["Qub"] = mock.Mock()
sys.modules["Qub.CTools"] = mock.Mock()

mxcube = None
server = None


def parse_args(argv):
XML_DIR = os.path.join(
Expand Down Expand Up @@ -103,9 +101,6 @@ def parse_args(argv):


def build_server_and_config(test=False, argv=None):
global mxcube
global server

cmdline_options = parse_args(argv)

try:
Expand All @@ -116,9 +111,6 @@ def build_server_and_config(test=False, argv=None):
return (None, None)

try:
mxcube = MXCUBEApplication()
server = Server()

# This refactoring (with other bits) allows you to pass a 'path1:path2' lookup path
# as the hwr_directory. I need it for sensible managing of a multi-beamline test set-up
# without continuously editing teh main config files.
Expand All @@ -131,9 +123,9 @@ def build_server_and_config(test=False, argv=None):
if test:
cfg.flask.USER_DB_PATH = "/tmp/mxcube-test-user.db"

server.init(cmdline_options, cfg, mxcube)
mxcube.init(
server,
Server.init(cmdline_options, cfg, MXCUBEApplication)
MXCUBEApplication.init(
Server,
cmdline_options.allow_remote,
cmdline_options.ra_timeout,
cmdline_options.log_file,
Expand All @@ -142,12 +134,12 @@ def build_server_and_config(test=False, argv=None):
cfg,
)

server.register_routes(mxcube)
Server.register_routes(MXCUBEApplication)
except Exception:
traceback.print_exc()
raise

return (server, cfg)
return (Server, cfg)


def main():
Expand Down
4 changes: 3 additions & 1 deletion mxcube3/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ def init(
MXCUBEApplication.init_state_storage()

# MXCUBEApplication.load_settings()
msg = "MXCuBE 3 initialized, it took %.1f seconds" % (time.time() - MXCUBEApplication.t0)
msg = "MXCuBE 3 initialized, it took %.1f seconds" % (
time.time() - MXCUBEApplication.t0
)
logging.getLogger("MX3.HWR").info(msg)

@staticmethod
Expand Down
1 change: 0 additions & 1 deletion mxcube3/core/components/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def db_add_message(self, user, message):
self.app.server.user_datastore.add_message_to_user(_user, _m)

def append_message(self, message, user):

data = {
"message": message,
"username": user.username,
Expand Down
9 changes: 5 additions & 4 deletions mxcube3/core/components/samplechanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ def get_initial_state(self):
def sync_with_crims(self):
"""
To be use mostly when Diffractometer is in plate mode
This retun a List of crystal dict available in Crims that have been Harvested
With this user can visualize easier where the crystal are in Plate GUI
This retun a List of crystal dict available in Crims that have been Harvested
With this user can visualize easier where the crystal are in Plate GUI
"""
xtal_list = []
try:
Expand All @@ -370,7 +370,7 @@ def sync_with_crims(self):
"offset_y": x.offset_y,
"image_url": x.image_url,
"image_date": x.image_date,
"sample": x.sample
"sample": x.sample,
}
xtal_list.append(response)
res = {"xtal_list": xtal_list}
Expand All @@ -382,7 +382,7 @@ def sync_with_crims(self):

def queue_mount_sample(view, data_model, centring_done_cb, async_result):
from mxcube3.routes import signals
from mxcube3 import mxcube
from mxcube3.app import MXCUBEApplication as mxcube

HWR.beamline.sample_view.clear_all()
logging.getLogger("user_level_log").info("Loading sample ...")
Expand Down Expand Up @@ -516,6 +516,7 @@ def queue_mount_sample(view, data_model, centring_done_cb, async_result):
else:
dm.disconnect("centringAccepted", centring_done_cb)


def patch_queue_entry_mount_sample():
# Important, patch queue_entry.mount_sample with the mount_sample defined above
queue_entry.base_queue_entry.mount_sample = queue_mount_sample
2 changes: 1 addition & 1 deletion mxcube3/core/components/sampleview.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def save_snapshot(self, filename, bw=False):
# _do_take_snapshot(filename, bw)

def take_snapshots(self, snapshots=None, _do_take_snapshot=_do_take_snapshot):
from mxcube3 import mxcube
from mxcube3.app import MXCUBEApplication as mxcube

if snapshots is None:
# called via AbstractCollect
Expand Down
4 changes: 2 additions & 2 deletions mxcube3/routes/signals.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import json

from mxcube3 import server
from mxcube3 import mxcube
from mxcube3.server import Server as server
from mxcube3.app import MXCUBEApplication as mxcube

from flask import Response

Expand Down
4 changes: 2 additions & 2 deletions mxcube3/state_storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask_socketio import emit
from mxcube3 import server
from mxcube3 import mxcube
from mxcube3.server import Server as server
from mxcube3.app import MXCUBEApplication as mxcube

import json

Expand Down

0 comments on commit 6ed6f7c

Please sign in to comment.