Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upgitpython's clone_from() throws exceptions while cloning a repo when called through an flask API #1020
Comments
Thanks for posting. Could you provide more details as to how the exception looks like? Maybe that gives a hint on solving this issue, for now I am absolutely puzzled and wouldn't know what GitPython should do in an environment like this. |
@Byron Thanks for helping out. Here is the ERROR I'm getting in the output of the API call.
Here is the sample output of a successful call:
|
This part of the code is erroring out. Lines 953 to 960 in 24cd6da |
This issue is resolved now.
This did the trick and the code now works in a daemonized environment as well. What I do want to understand, why is git clone functionality expecting some handler to listen to its outputs and raising exceptions based on it. Why don't execute the command and give back the output without checking for listeners? |
I am glad there is a way! A handler is required only if live-progress is desired by the caller, after all initial clones can take a very long time. The alternative branch uses Lastly GitPython doesn't do anything special, it merely connects pipes to stdout and stderr to be able to intercept them. If that doesn't work because a parent-process changes the way spawn works, GitPython cannot work. Please let me know if you come across a way to spawn processes in a way that would work naturally in such a context. Without such a capability, I believe there is nothing else that can be done here. |
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:
ERROR:
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?