sys.stdout.flush solves the issue of the restful program seemingly blocking