Skip to content

Commit ec6a017

Browse files
Adding starting pyro name-server from command itslef (#98)
1 parent 19fe785 commit ec6a017

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ requires-python = ">=3.10"
4747
license = {text = "MIT"}
4848

4949
[project.scripts]
50-
autoplot = "scripts.monitr_server:run_autoplot"
50+
autoplot = "scripts.monitr_server:run_autoplot"
51+
pyro-ns = "scripts.pyro_nameserver:run_pyro_nameserver"

scripts/pyro_nameserver.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import argparse
2+
import logging
3+
import os
4+
import sys
5+
6+
# Configure logging to output to console
7+
logging.basicConfig(
8+
level=logging.INFO,
9+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
10+
)
11+
logger = logging.getLogger(__name__)
12+
13+
14+
def run_pyro_nameserver():
15+
"""
16+
Run the Pyro4 nameserver directly in the terminal.
17+
This allows stopping the server with Ctrl+C.
18+
"""
19+
parser = argparse.ArgumentParser(
20+
description="Start Pyro4 nameserver for QICK integration. "
21+
"The nameserver runs in the foreground and can be stopped with Ctrl+C."
22+
)
23+
parser.add_argument(
24+
'--host',
25+
'-n',
26+
default='localhost',
27+
help='Host address for the nameserver (default: localhost)'
28+
)
29+
parser.add_argument(
30+
'--port',
31+
'-p',
32+
type=int,
33+
default=8888,
34+
help='Port number for the nameserver (default: 8888)'
35+
)
36+
37+
args = parser.parse_args()
38+
39+
# Set required environment variables for Pyro4
40+
os.environ["PYRO_SERIALIZERS_ACCEPTED"] = "pickle"
41+
os.environ["PYRO_PICKLE_PROTOCOL_VERSION"] = "4"
42+
43+
logger.info(f"Starting Pyro4 nameserver on {args.host}:{args.port}")
44+
logger.info("Press Ctrl+C to stop the nameserver")
45+
46+
# Build the command to execute pyro4-ns
47+
cmd = [
48+
"pyro4-ns",
49+
"-n",
50+
args.host,
51+
"-p",
52+
str(args.port),
53+
]
54+
55+
try:
56+
# Replace the current process with pyro4-ns
57+
# This will run pyro4-ns directly in the terminal
58+
os.execvp("pyro4-ns", cmd)
59+
except FileNotFoundError:
60+
logger.error("pyro4-ns command not found. Please install Pyro4 with: pip install Pyro4")
61+
sys.exit(1)
62+
except Exception as e:
63+
logger.error(f"Failed to start Pyro4 nameserver: {e}")
64+
logger.error(f"Error type: {type(e).__name__}")
65+
import traceback
66+
traceback.print_exc()
67+
sys.exit(1)
68+
69+
70+
if __name__ == "__main__":
71+
run_pyro_nameserver()

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ labcore =
5151
[options.entry_points]
5252
console_scripts =
5353
reconstruct-data = scripts.reconstruct_safe_write_data:main
54-
autoplot = scripts.monitr_server:run_autoplot
54+
autoplot = scripts.monitr_server:run_autoplot
55+
pyro-ns = scripts.pyro_nameserver:run_pyro_nameserver

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
entry_points={
88
'console_scripts': [
99
'autoplot = scripts.monitr_server:run_autoplot',
10+
'pyro-ns = scripts.pyro_nameserver:run_pyro_nameserver',
1011
],
1112
},
1213
)

0 commit comments

Comments
 (0)