Skip to content

Commit 5a13cdc

Browse files
carlescufihenrikbrixandersen
authored andcommitted
scripts: trace_usb_capture: Clean up on exit
When the user presses Ctrl+c to exit the infinite capturing loop, ensure that the cleanup funciton is always executed. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
1 parent 8ab712a commit 5a13cdc

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

scripts/tracing/trace_capture_usb.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ def main():
8686
buff = usb.util.create_buffer(8192)
8787
read_endpoint.read(buff, 10000)
8888

89-
with open(output_file, "wb") as file_desc:
90-
while True:
91-
buff = usb.util.create_buffer(8192)
92-
length = read_endpoint.read(buff, 100000)
93-
for index in range(length):
94-
file_desc.write(chr(buff[index]).encode('latin1'))
95-
96-
usb.util.release_interface(usb_device, interface)
97-
98-
if __name__=="__main__":
9989
try:
100-
main()
90+
with open(output_file, "wb") as file_desc:
91+
while True:
92+
buff = usb.util.create_buffer(8192)
93+
length = read_endpoint.read(buff, 100000)
94+
for index in range(length):
95+
file_desc.write(chr(buff[index]).encode('latin1'))
10196
except KeyboardInterrupt:
97+
pass
98+
finally:
10299
print('Data capture interrupted, data saved into {}'.format(args.output))
103-
sys.exit(0)
100+
usb.util.release_interface(usb_device, interface)
101+
102+
if __name__=="__main__":
103+
main()

0 commit comments

Comments
 (0)