Repository navigation
Issues with AutoInterrupt in conjunction with sys.exit on python 3.5 #463
Description
Activity
I recall from reading another isssue that the problem is that the process object is not being deleted
quickly under python3. This is because of the change in garbage collection between py2 and py3.Looking at the code it looks like the fix is to explicitly del the process object once it is no longer needed.
This bug I suspect may happen on py2 depending on garbage collector config.
for example from cmd.py:965:
def __get_object_header(self, cmd, ref): cmd.stdin.write(self._prepare_ref(ref)) cmd.stdin.flush() return self._parse_object_header(cmd.stdout.readline())should be something along these lines:
def __get_object_header(self, cmd, ref): cmd.stdin.write(self._prepare_ref(ref)) cmd.stdin.flush() result = self._parse_object_header(cmd.stdout.readline()) del cmd return cmdWhich version of GitPython are you using ? It doesn't appear to be the latest one.
The line in question has recently be fixed to check for all the eventualities.
Thanks for the clarification.Closed due to inactivity. Please comment to get the issue reopened.
Byron,
Unless you fixed the code this bug is still present in the code base.
Barry
@barry-scott Can you please answer the question in my last comment, or maybe even provide a test that triggers the issue to allow it to be fixed ? Otherwise this one would be open forever, and I try to avoid that. Thank you.
And I just noticed that you have not been the OP, yet it seemed you have information about the issue that might help resolving it.
What I recall is that I noticed is the with python2 as soon as the object owning a process resource goes out of scope its is deleted. But in python3 the delete is delayed because of changes in garbage collection.
To force the clean up all objects that control a process resource must be delete explicitly using del procFor example line 635 in cmd..py returns an instance of AutoInterrupt. All caller will have to be changed to del the returned object after use.
Unless this code change has been made this bug remains unfixed.
Thanks @barry-scott, I understand. It seems a context manager for the
Cmdobject would be an excellent addition to its API.25 remaining items
- modified the milestones: This milestone has been deleted, This milestone has been deleted
on Mar 8, 2017 I am closing this issue as it had no interaction for more than 3 months. Please feel free to comment in case you need it to be reopened.
I am getting this error on apache with mod_wsgi on Redhat 7.2 with python 3.6 ... latest version of gitpython
[Fri Jun 08 13:03:17.584493 2018] [wsgi:error] [pid 21167] [client 10.53.9.7:33473] 2018-06-08 13:03:17,584 - ProcessGit - INFO - push:[]
[Fri Jun 08 13:07:38.056054 2018] [mpm_prefork:notice] [pid 21166] AH00170: caught SIGWINCH, shutting down gracefully
Exception ignored in: <bound method Repo.del of <git.Repo "/opt/xxx/cloud_automation/micro-services/scmprojects/resources/SRV-003106/tst8y9u/.git">>
Traceback (most recent call last):
File "/usr/venv/lib/python3.6/site-packages/git/repo/base.py", line 200, in del
NameError: name 'Exception' is not defined
Exception ignored in: <bound method Popen.del of <subprocess.Popen object at 0x7f0ec97652e8>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/subprocess.py", line 761, in del
NameError: name 'ResourceWarning' is not defined
Exception ignored in: <bound method Popen.del of <subprocess.Popen object at 0x7f0ec97659e8>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/subprocess.py", line 761, in del
NameError: name 'ResourceWarning' is not defined
Exception ignored in: <bound method Git.AutoInterrupt.del of <git.cmd.Git.AutoInterrupt object at 0x7f0ec9765390>>
Traceback (most recent call last):
File "/usr/venv/lib/python3.6/site-packages/git/cmd.py", line 372, in del
NameError: name 'getattr' is not defined#-> /usr/sbin/httpd -V
Server version: Apache/2.4.6 (Red Hat Enterprise Linux)
Server built: Sep 17 2015 09:06:30
Server's Module Magic Number: 20120211:24
Server loaded: APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"@hobbitten123 Depending on your usecase, you might also be able to eventually use https://github.com/Byron/grit-rs , which I just declared the spiritual successor of
GitPython.Well, it happened to me too. Using python 3.7.3, gitpython 2.1.11, git 2.15.1.windows.1 on Windows10 and running everything from git bash GNU bash, version 4.4.12(1)-release (x86_64-pc-msys)
The app has many checks for existing files and uses sys.exit('error message') if some checks fail.
If everything goes well the app adds a list of files and commits them. Everything used to be smooth when there was only one file added and committed, but when I started having two files added and committed I got this error:
Exception ignored in: <function Git.AutoInterrupt.__del__ at 0x000001994C652488> Traceback (most recent call last): File "C:\Users\luca.zamboni\AppData\Local\Programs\Python\Python37\lib\site-packages\git\cmd.py", line 368, in __del__ if proc.poll() is not None: File "C:\Users\luca.zamboni\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 966, in poll return self._internal_poll() File "C:\Users\luca.zamboni\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1216, in _internal_poll if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0: OSError: [WinError 6] The handle is invalidThe part of the app causing the error is this one:
############################################################################ # Commit the review list file AND the review report file # ############################################################################ # get the file relative to repo root WPRRlist_path_git = to_native_path_linux(os.path.relpath(os.path.realpath(WPRRlist_path), repo_rootpath)) # reviews list WPRR_path_git = to_native_path_linux(os.path.relpath(os.path.realpath(WPRR_newpath), repo_rootpath)) # review report repo.index.add([WPRRlist_path_git, WPRR_path_git]) repo.index.commit(str(repo_path_git)+' review ' + str(result).upper() + 'ED; report: ' + str(WPRR_path_git) + '\n\n' + str(comment)) print('Report moved to '+WPRR_path_git+' and review committed. You can still go back by discharging this commit.') ############################################################################ # END # ############################################################################ exit(0)The original with only one file added and committed was:
############################################################################ # Commit the review list file # ############################################################################ # get the file relative to repo root review_repo_path = os.path.relpath(os.path.realpath(csvrevpath), repo_rootpath) # rel path repo.index.add([to_native_path_linux(review_repo_path)]) repo.index.commit(str(repo_path_git)+' review ' + str(result).upper() + 'ED\n\n' + str(comment)) print('Review committed. You can still go back by discharging this commit.') ############################################################################ # END # ############################################################################ exit(0)After reading #718 I added a manual deletion of the repo git object and everything works smooth.
############################################################################ # Commit the review list file AND the review report file # ############################################################################ # get the file relative to repo root WPRRlist_path_git = to_native_path_linux(os.path.relpath(os.path.realpath(WPRRlist_path), repo_rootpath)) # reviews list WPRR_path_git = to_native_path_linux(os.path.relpath(os.path.realpath(WPRR_newpath), repo_rootpath)) # review report repo.index.add([WPRRlist_path_git, WPRR_path_git]) repo.index.commit(str(repo_path_git)+' review ' + str(result).upper() + 'ED; report: ' + str(WPRR_path_git) + '\n\n' + str(comment)) print('Report moved to '+WPRR_path_git+' and review committed. You can still go back by discharging this commit.') ############################################################################ # END # ############################################################################ repo.__del__() exit(0)So as a workaround manually calling del() before calling exit(0) works.
The destructor of the cmd class (actually AutoInterrupt) seems to throw some errors using python 3.5 on Arclinux:
It seems this error is triggered by a call to sys.exit(0) at the end of my script, since it doesn't appear if I comment it out.
However I couldn't reproduce this behavior with python 2.7, here sys.exit(0) seems to be working with the module correctly.
What I do is simply clone a repo, add some files commit and push them to a remote.