aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_hwd.py
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2018-01-09 17:49:34 -0800
committerMartin Braun <martin.braun@ettus.com>2018-01-10 17:29:49 -0800
commit0691c5ea752139e44605004a3c2d8a5fe493934d (patch)
treeb801b2684dac58496ef5f39565ee3983a0700b28 /mpm/python/usrp_hwd.py
parentc5acc08e671f1797f3130657eec48f48ffa51bf7 (diff)
downloaduhd-0691c5ea752139e44605004a3c2d8a5fe493934d.tar.gz
uhd-0691c5ea752139e44605004a3c2d8a5fe493934d.tar.bz2
uhd-0691c5ea752139e44605004a3c2d8a5fe493934d.zip
mpm: Spawn periph manager inside the RPC process
Reviewed-by: Brent Stapleton <brent.stapleton@ettus.com>
Diffstat (limited to 'mpm/python/usrp_hwd.py')
-rwxr-xr-xmpm/python/usrp_hwd.py87
1 files changed, 48 insertions, 39 deletions
diff --git a/mpm/python/usrp_hwd.py b/mpm/python/usrp_hwd.py
index 82b1ecd93..4036a1084 100755
--- a/mpm/python/usrp_hwd.py
+++ b/mpm/python/usrp_hwd.py
@@ -15,11 +15,9 @@ from gevent import signal
from gevent.hub import BlockingSwitchOutError
import usrp_mpm as mpm
from usrp_mpm.mpmtypes import SharedState
-from usrp_mpm.periph_manager import periph_manager
_PROCESSES = []
-
def setup_arg_parser():
"""
Create an arg parser
@@ -107,58 +105,69 @@ def kill_time(sig, frame):
log.info("System exiting")
sys.exit(0)
-
-def main():
+def init_only(log, args):
"""
- Go, go, go!
-
- Main process loop.
+ Run the full initialization immediately and return
"""
- args = parse_args()
- log = mpm.get_main_logger(
- log_default_delta=args.verbose-args.quiet
- ).getChild('main')
- shared = SharedState()
# Create the periph_manager for this device
# This call will be forwarded to the device specific implementation
# e.g. in periph_manager/n310.py
- # Which implementation is called will be determined during configuration
- # with cmake (-DMPM_DEVICE).
- # mgr is thus derived from PeriphManagerBase (see periph_manager/base.py)
+ # Which implementation is called will be determined during
+ # configuration with cmake (-DMPM_DEVICE).
+ # mgr is thus derived from PeriphManagerBase
+ # (see periph_manager/base.py)
+ from usrp_mpm.periph_manager import periph_manager
log.info("Spawning periph manager...")
- mgr_generator = lambda: periph_manager(args)
- mgr = mgr_generator()
- discovery_info = {
- "type": mgr.get_device_info().get("type", "n/a"),
- "serial": mgr.get_device_info().get("serial", "n/a"),
- "product": mgr.get_device_info().get("product", "n/a")
- }
- if args.init_only:
- init_time_start = time.time()
- init_result = mgr.init(args.default_args)
- init_duration = time.time() - init_time_start
- if init_result:
- log.info("Initialization successful! Duration: {:.02f} s"
- .format(init_duration))
- else:
- log.warning("Initialization failed! Duration: {:.02f} s"
- .format(init_duration))
- log.info("Terminating on user request before launching RPC server.")
- mgr.deinit()
- return init_result
+ ctor_time_start = time.time()
+ mgr = periph_manager(args)
+ ctor_duration = time.time() - ctor_time_start
+ log.info("Ctor Duration: {:.02f} s".format(ctor_duration))
+ init_time_start = time.time()
+ init_result = mgr.init(args.default_args)
+ init_duration = time.time() - init_time_start
+ if init_result:
+ log.info("Initialization successful! Duration: {:.02f} s"
+ .format(init_duration))
+ else:
+ log.warning("Initialization failed! Duration: {:.02f} s"
+ .format(init_duration))
+ log.info("Terminating on user request before launching RPC server.")
+ mgr.deinit()
+ return init_result
+
+def spawn_processes(log, args):
+ """
+ Launch the subprocesses and hang until completion.
+ """
+ shared = SharedState()
+ log.info("Spawning RPC process...")
+ _PROCESSES.append(
+ mpm.spawn_rpc_process(mpm.mpmtypes.MPM_RPC_PORT, shared, args))
log.info("Spawning discovery process...")
_PROCESSES.append(
- mpm.spawn_discovery_process(discovery_info, shared, args.discovery_addr)
+ mpm.spawn_discovery_process(shared, args.discovery_addr)
)
- log.info("Spawning RPC process...")
- _PROCESSES.append(
- mpm.spawn_rpc_process(mpm.mpmtypes.MPM_RPC_PORT, shared, mgr, mgr_generator))
log.info("Processes launched. Registering signal handlers.")
signal.signal(signal.SIGTERM, kill_time)
signal.signal(signal.SIGINT, kill_time)
signal.pause()
return True
+
+def main():
+ """
+ Go, go, go!
+
+ Main process loop.
+ """
+ args = parse_args()
+ log = mpm.get_main_logger(
+ log_default_delta=args.verbose-args.quiet
+ ).getChild('main')
+ if args.init_only:
+ return init_only(log, args)
+ return spawn_processes(log, args)
+
if __name__ == '__main__':
exit(not main())