Skip to contentSkip to conversation

bbremote: fix the exit usage

PATCH In review Marco Felsch 3 participants 3 messages Feb 24, 2021 – Mar 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bbremote: fix the exit usage

Unlike the sys.exit() function the builtin exit() function don't take an argument. Fix it by using the exit function from the sys module which is already imported.

---
 scripts/remote/main.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
scripts/remote/main.py +5 -5
index cef5d92ee2..37be5a35f0 100644
@@ -14,7 +14,7 @@ try:
     import serial
 except:
     print("error: No python-serial package found", file=sys.stderr)
-    exit(2)
+    sys.exit(2)
 
 
 def versiontuple(v):
@@ -279,15 +279,15 @@ logging.basicConfig(level=VERBOSITY[args.verbose],
                     format='%(levelname)-8s %(module)-8s %(funcName)-16s %(message)s')
 try:
     res = args.func(args)
-    exit(res)
+    sys.exit(res)
 except RatpError as detail:
     print("Ratp error:", detail, file=sys.stderr);
-    exit(127)
+    sys.exit(127)
 except KeyboardInterrupt:
     print("\nInterrupted", file=sys.stderr);
-    exit(1)
+    sys.exit(1)
 #try:
 #    res = args.func(args)
 #except Exception as e:
 #    print("error: failed to establish connection: %s" % e, file=sys.stderr)
-#    exit(2)
+#    sys.exit(2)
Signature · 7 lines
2.29.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

Hi,

Quoted 3 lines · Marco Felsch

Unlike the sys.exit() function the builtin exit() function don't take an argument. Fix it by using the exit function from the sys module which is already imported.

This is not entirely correct, the builtin exit() function also takes an exit code and works fine when I tested this:

  $ python3 -c "exit(1)"; echo $?
  1
  $

Nevertheless the documentation [1] says that sys.exit() should be used in scripts. So the patch is fine, but the justification not entirely correct.

[1]: https://docs.python.org/3/library/constants.html#constants-added-by-the-site-module

Regards,
Rouven Czerwinski

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw

Marco,

Quoted 14 lines · Rouven Czerwinski

Hi,

Quoted 3 lines · Marco Felsch

Unlike the sys.exit() function the builtin exit() function don't take an argument. Fix it by using the exit function from the sys module which is already imported.

This is not entirely correct, the builtin exit() function also takes an exit code and works fine when I tested this:

  $ python3 -c "exit(1)"; echo $?
  1
  $
Quoted 5 lines

Nevertheless the documentation [1] says that sys.exit() should be used in scripts. So the patch is fine, but the justification not entirely correct.

[1]: https://docs.python.org/3/library/constants.html#constants-added-by-the-site-module

Could you adjust the commit message accordingly?

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox