-
-
Notifications
You must be signed in to change notification settings - Fork 964
Description
I have python snippet which clones a github repo over https access tokens, creates a branch modifies the content, and pushes back. Below code works perfectly fine if run directly via python interpreter on command line. But I have a use case where I m exposing this functionality as an API via python's flask server. Flask server is run through a python's "gunicorn" framework which is a Python WSGI HTTP Server. Now when I use the API call, it is throwing errors while cloning the repo. I have tested it by only running the flask server and the API call works perfectly fine and does the work without raising exceptions. But the same Flask API when run through Python's gunicorn I m getting this error.
Not sure how to get rid of that error.
Code Snippet:
import git
.........
.........
.........
try:
_repo = git.Repo.clone_from(
f"https://{_token}:x-oauth-basic@{self.git_url}", _repo_dir
)
_new_branch = _repo.create_head(_branch)
_repo.head.set_reference(_new_branch)
except Exception as e:
return False, str(e)
_update_path = os.path.join(
_repo_dir, f"repo1/config/"
)
if not os.path.exists(_update_path):
os.mkdir(_update_path)
with open(f"{_update_path}/users.json", "w+") as _fd:
json.dump(_users_json, _fd, indent=4)
_repo.git.add(A=True)
_repo.git.commit(m=_title)
_repo.git.push("origin", _branch)
ERROR:
2020-06-11 17:18:16,714 DEBUG: Popen(['git', 'clone', '-v', 'https://<ACCESS_TOKEN>:x-oauth-basic@github.com/ganesh/repo1.git', '/tmp/folder-1234_1591895896.185123'], cwd=/opt/ganesh, universal_newlines=True, shell=None, istream=None)
2020-06-11 17:18:16,739 DEBUG: Cmd(['git', 'clone', '-v', 'https://<ACCESS_TOKEN>:x-oauth-basic@github.com/ganesh/repo1.git', '/tmp/folder-1234_1591895896.185123'])'s unused stdout: Cloning into '/tmp/folder-1234_1591895896.185123'...
2020-06-11 17:18:16,740 DEBUG: AutoInterrupt wait stderr: b'Error reading command stream\n'
It looks more like gitpython is outputting something while doing the clone as a stream and nothing is reading/listening to it and it goes and raise an exception? This issue is not faced while directly cloning the repo using the commands in debug log nor when running the script via python interpreter directly. I believe this is happening because gunicorn is a WSGI HTTP Server in which case the processes spawned are handed over to Unix systems Init process (PID 1)
How this exception can be disabled for applications running behind gunicorn or anything which works more like an HTTP server? or Can this be better addressed in later versions?