-
Notifications
You must be signed in to change notification settings - Fork 14
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
karabo-bridge-serve-run command #458
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a0f059c
Split out serve_data function and show moree info while streaming
takluyver e97f0cb
Fix getting length of deque
takluyver 2d4f64d
Print final update when streaming finishes
takluyver eae9935
Add karabo-bridge-serve-run command
takluyver 0e3d0df
karabo-bridge-serve-run: only send complete trains by default
takluyver a67217f
Fix parameters to serve_data()
takluyver cda0b9c
Ensure print_update() can't have an undefined variable
takluyver 73208fc
Make --port an option
takluyver 10f145a
Document karabo-bridge-serve-run command
takluyver 4554836
Add a test for karabo-bridge-serve-run
takluyver 505aa3b
Simplify test
takluyver a46793d
Recreate raw+proc folder tree for each test using it
takluyver f15401c
Give test subprocesses a chance to exit cleanly
takluyver 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 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from argparse import ArgumentParser | ||
import sys | ||
|
||
from .. import open_run | ||
|
||
IMPORT_FAILED_MSG = """\ | ||
{} | ||
|
||
karabo-bridge-serve-run requires additional dependencies: | ||
pip install karabo-bridge psutil | ||
""" | ||
|
||
def main(argv=None): | ||
ap = ArgumentParser(prog="karabo-bridge-serve-run") | ||
ap.add_argument("proposal", help="Proposal number") | ||
ap.add_argument("run", help="Run number") | ||
ap.add_argument("port", help="TCP port or ZMQ endpoint to send data on") | ||
ap.add_argument( | ||
"--include", help="Select matching sources (and optionally keys) to " | ||
"include in streamed data", | ||
action='append' | ||
) | ||
ap.add_argument( | ||
"--append-detector-modules", help="combine multiple module sources" | ||
" into one (will only work for AGIPD data currently).", | ||
action='store_true' | ||
) | ||
ap.add_argument( | ||
"--dummy-timestamps", help="create dummy timestamps if the meta-data" | ||
" lacks proper timestamps", | ||
action='store_true' | ||
) | ||
ap.add_argument( | ||
"--use-infiniband", help="Use infiniband interface if available " | ||
"(if a TCP port is specified)", | ||
action='store_true' | ||
) | ||
ap.add_argument( | ||
"-z", "--socket-type", help="ZeroMQ socket type", | ||
choices=['PUB', 'PUSH', 'REP'], default='REP' | ||
) | ||
args = ap.parse_args(argv) | ||
|
||
try: | ||
from ..export import serve_data | ||
except ImportError as e: | ||
sys.exit(IMPORT_FAILED_MSG.format(e)) | ||
|
||
run = open_run(args.proposal, args.run, data='all') | ||
|
||
if not args.include: | ||
print("Available sources:") | ||
for s in sorted(run.all_sources): | ||
print(f" {s}") | ||
sys.exit("Please select at least one source with --include") | ||
|
||
include = [] | ||
for pat in args.include: | ||
if '[' in pat: | ||
if not pat.endswith(']'): | ||
sys.exit(f"Missing final ] in {pat!r}") | ||
src_pat, key_pat = pat[:-1].split('[', 1) | ||
include.append((src_pat, key_pat)) | ||
else: | ||
# Source pattern only | ||
include.append(pat) | ||
|
||
sel = run.select(include) | ||
|
||
try: | ||
serve_data( | ||
sel, source_glob=args.source, key_glob=args.key, | ||
append_detector_modules=args.append_detector_modules, | ||
dummy_timestamps=args.dummy_timestamps, | ||
use_infiniband=args.use_infiniband, sock=args.socket_type | ||
) | ||
except KeyboardInterrupt: | ||
print('\nStopped.') | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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
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.
What is the reason to do this import here within the function and not at the top of the file? (except of course the fail message constant needs to be defined first)
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.
I'd usually try to avoid side-effects (like
sys.exit()
) when loading a module, although it doesn't matter so much for a module defining a CLI like this. It's also handy that--help
still works even without the extra dependencies.We could still have the import at the top like this:
But that looks less neat to me.