diff --git a/fdroid b/fdroid index d0924b4d..1ac34b53 100755 --- a/fdroid +++ b/fdroid @@ -149,9 +149,7 @@ def main(): sys.exit(1) except KeyboardInterrupt: print('') - sys.stdout.flush() - sys.stderr.flush() - os._exit(1) + fdroidserver.common.force_exit(1) # These should only be unexpected crashes due to bugs in the code # str(e) often doesn't contain a reason, so just show the backtrace except Exception as e: diff --git a/fdroidserver/build.py b/fdroidserver/build.py index a4d1c6d2..375003e3 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -1148,7 +1148,7 @@ def main(): appid, reason)) if options.stop: logging.debug("Error encoutered, stopping by user request.") - sys.exit(1) + common.force_exit(1) failed_apps[appid] = vcse wikilog = str(vcse) except FDroidException as e: @@ -1163,7 +1163,7 @@ def main(): logging.error("Could not build app %s: %s" % (appid, e)) if options.stop: logging.debug("Error encoutered, stopping by user request.") - sys.exit(1) + common.force_exit(1) failed_apps[appid] = e wikilog = e.get_wikitext() except Exception as e: @@ -1171,7 +1171,7 @@ def main(): appid, traceback.format_exc())) if options.stop: logging.debug("Error encoutered, stopping by user request.") - sys.exit(1) + common.force_exit(1) failed_apps[appid] = e wikilog = str(e) @@ -1238,7 +1238,7 @@ def main(): if not os.path.isdir(repo_dir): logging.critical("directory does not exists '{path}'".format(path=repo_dir)) - sys.exit(1) + common.force_exit(1) logging.info("Performing Drozer scan on {0}.".format(app)) docker.perform_drozer_scan(apk_path, app.id, repo_dir) @@ -1289,9 +1289,7 @@ def main(): newpage.save('#REDIRECT [[' + wiki_page_path + ']]', summary='Update redirect') # hack to ensure this exits, even is some threads are still running - sys.stdout.flush() - sys.stderr.flush() - os._exit(0) + common.force_exit() if __name__ == "__main__": diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 81da0cb8..137563d7 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -3424,3 +3424,16 @@ def calculate_math_string(expr): raise SyntaxError("could not parse expression '{expr}', " "only basic math operations are allowed (+, -, *)" .format(expr=expr)) + + +def force_exit(exitvalue=0): + """force exit when thread operations could block the exit + + The build command has to use some threading stuff to handle the + timeout and locks. This seems to prevent the command from + exiting, unless this hack is used. + + """ + sys.stdout.flush() + sys.stderr.flush() + os._exit(exitvalue)