Check the return code before writing PID file in Python start_app()