-
Notifications
You must be signed in to change notification settings - Fork 78
ENH: Make deferring connections the default for main window again for better performance #974
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
46c5a15
42058af
c1598c9
1ca0f77
0ba4f06
30921b0
4f361a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,14 @@ | |
from io import StringIO | ||
from os import path | ||
from string import Template | ||
from typing import Dict, Optional, Tuple | ||
from typing import Dict, List, Optional, Tuple | ||
|
||
import re | ||
import six | ||
from qtpy import uic | ||
from qtpy.QtWidgets import QApplication, QWidget | ||
|
||
from . import data_plugins | ||
from .utilities import import_module_by_filename, is_pydm_app, macro | ||
|
||
|
||
|
@@ -28,7 +29,11 @@ class ScreenTarget: | |
logger = logging.getLogger(__file__) | ||
|
||
|
||
def load_file(file, macros=None, args=None, target=ScreenTarget.NEW_PROCESS): | ||
def load_file(file: str, | ||
macros: Optional[Dict[str, str]] = None, | ||
args: Optional[List[str]] = None, | ||
target: ScreenTarget = ScreenTarget.NEW_PROCESS, | ||
defer_connections: bool = False): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a sensible default, retaining previous behavior 👍 |
||
""" | ||
Load .ui, .py, or .adl screen file, perform macro substitution, then return | ||
the resulting QWidget. | ||
|
@@ -47,6 +52,11 @@ def load_file(file, macros=None, args=None, target=ScreenTarget.NEW_PROCESS): | |
target : int | ||
One of the ScreenTarget targets. PROCESS is only available when used | ||
with PyDM Application for now. | ||
defer_connections : bool | ||
If set to true, the loading of channel connections will be deferred until the | ||
connection queue is flushed via a data_plugins.establish_queued_connections() call. This | ||
results in the display being responsive to the user faster as it does not wait on | ||
establishing connections during initial display creation. | ||
|
||
Returns | ||
------- | ||
|
@@ -66,7 +76,8 @@ def load_file(file, macros=None, args=None, target=ScreenTarget.NEW_PROCESS): | |
_, extension = os.path.splitext(file) | ||
loader = _extension_to_loader.get(extension, load_py_file) | ||
logger.debug("Loading %s file by way of %s...", file, loader.__name__) | ||
w = loader(file, args=args, macros=macros) | ||
with data_plugins.connection_queue(defer_connections=defer_connections): | ||
w = loader(file, args=args, macros=macros) | ||
if target == ScreenTarget.DIALOG: | ||
w.show() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from .widgets.rules import register_widget_rules, unregister_widget_rules | ||
from . import config | ||
import subprocess | ||
import threading | ||
import platform | ||
import logging | ||
|
||
|
@@ -352,7 +353,8 @@ def open(self, filename, macros=None, args=None, target=None): | |
new_widget = load_file(filename, | ||
macros=macros, | ||
args=args, | ||
target=target) | ||
target=target, | ||
defer_connections=True) | ||
if new_widget: | ||
if self.home_widget is None: | ||
self.home_widget = new_widget | ||
|
@@ -370,6 +372,10 @@ def open(self, filename, macros=None, args=None, target=None): | |
self.ui.actionEdit_in_Designer.setText(edit_in_text) | ||
if (self.designer_path and ui_file) or (py_file and not ui_file): | ||
self.ui.actionEdit_in_Designer.setEnabled(True) | ||
|
||
# Create and run the thread for establishing the channel connections which have been queued above | ||
establish_connections_thread = threading.Thread(target=data_plugins.establish_queued_connections, daemon=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few thoughts here: If kept as-is:
|
||
establish_connections_thread.start() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A second thought, unrelated to the first:
|
||
return new_widget | ||
|
||
def load_tool(self, checked): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions that intend to act like queue handlers and modify global state concern me a bit.
Two threads that establish queued connections have the potential to fight each other in unexpected ways (unless you introduce locks, which is less than ideal too).
It might be wise to switch these to real queues