Skip to content

Commit 70bf4df

Browse files
authored
Merge pull request #148 from openxc/ctrl_c
Add a try catch for keyboardinterupt for both openxc-dump and scanner…
2 parents 0393ba9 + c43dd63 commit 70bf4df

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

openxc/tools/dump.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import argparse
1010
import time
1111
import logging
12+
import sys
1213

1314
from openxc.formats.json import JsonFormatter
1415
from .common import device_options, configure_logging, select_device
@@ -31,11 +32,14 @@ def parse_options():
3132

3233

3334
def main():
34-
configure_logging(logging.DEBUG)
35-
arguments = parse_options()
36-
37-
source_class, source_kwargs = select_device(arguments)
38-
source = source_class(callback=receive, **source_kwargs)
39-
source.start()
40-
# TODO test this, I'd prefer it to the sleep loop
41-
source.join()
35+
try:
36+
configure_logging(logging.DEBUG)
37+
arguments = parse_options()
38+
source_class, source_kwargs = select_device(arguments)
39+
source = source_class(callback=receive, **source_kwargs)
40+
source.start()
41+
# TODO test this, I'd prefer it to the sleep loop
42+
while(True):
43+
source.join(0.1)
44+
except KeyboardInterrupt:
45+
sys.exit(0)

openxc/tools/scanner.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module are internal only.
77
"""
88

9-
9+
import sys
1010
import argparse
1111
from collections import defaultdict
1212

@@ -98,11 +98,14 @@ def parse_options():
9898

9999

100100
def main():
101-
configure_logging()
102-
arguments = parse_options()
103-
104-
controller_class, controller_kwargs = select_device(arguments)
105-
controller = controller_class(**controller_kwargs)
106-
controller.start()
107-
108-
scan(controller, arguments.bus, arguments.message_id)
101+
try:
102+
configure_logging()
103+
arguments = parse_options()
104+
105+
controller_class, controller_kwargs = select_device(arguments)
106+
controller = controller_class(**controller_kwargs)
107+
controller.start()
108+
while(True):
109+
scan(controller, arguments.bus, arguments.message_id)
110+
except KeyboardInterrupt:
111+
sys.exit(0)

0 commit comments

Comments
 (0)