-
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
Draft
jbellister-slac
wants to merge
7
commits into
slaclab:master
Choose a base branch
from
jbellister-slac:defer_connections
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
46c5a15
ENH: Re-enable queued connections by default for a more responsive us…
jbellister-slac 42058af
DOC: Add a couple of doc strings
jbellister-slac c1598c9
TST: Add a simple test for loading a file with defer_connections set …
jbellister-slac 1ca0f77
STY: flake8 fixes
jbellister-slac 0ba4f06
MAINT: Store deferred connections in a Queue
jbellister-slac 30921b0
TST: Update defer connections test to use queue function
jbellister-slac 4f361a9
ENH: Move establishing the queued connecitons to the display itself
jbellister-slac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,10 +76,12 @@ 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() | ||
|
||
if defer_connections: | ||
data_plugins.establish_queued_connections() | ||
return w | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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