GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Issues with AutoInterrupt in conjunction with sys.exit on python 3.5 · Issue #463 · gitpython-developers/GitPython

Issues with AutoInterrupt in conjunction with sys.exit on python 3.5 #463

New issue
Copy link
New issue
Copy link
Closed
Closed
Issues with AutoInterrupt in conjunction with sys.exit on python 3.5#463
Copy link
Labels
acknowledgedwaiting for feedback
Milestone
v2.1.4 - Bugfixes

Description

@Heiko-san
Heiko-san
opened on Jun 6, 2016
Issue body actions

The destructor of the cmd class (actually AutoInterrupt) seems to throw some errors using python 3.5 on Arclinux:

Exception ignored in: <bound method Git.AutoInterrupt.__del__ of <git.cmd.Git.AutoInterrupt object at 0x7f7c2b101d68>>
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/git/cmd.py", line 294, in __del__
TypeError: 'NoneType' object is not callable
Exception ignored in: <bound method Git.AutoInterrupt.__del__ of <git.cmd.Git.AutoInterrupt object at 0x7f7c2b101cc0>>
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/git/cmd.py", line 294, in __del__
TypeError: 'NoneType' object is not callable

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.

...
repo = Repo.clone_from(target_git_path, target_temp_dir)
...
repo.index.add([file])
...
repo.index.commit('Initial commit')
...
refspec='refs/heads/{0}:refs/heads/{0}'.format(repo.active_branch) # this will fix error if user has set "push.default = matching"
repo.remotes.origin.push(refspec=refspec)

Activity

Next
  1. barry-scott commented on Jun 6, 2016

    @barry-scott
    barry-scott
    on Jun 6, 2016
    Contributor
    More actions

    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 cmd
    
  2. Byron
    added
    waiting for feedback
    on Jun 14, 2016
  3. Byron commented on Jun 14, 2016

    @Byron
    Byron
    on Jun 14, 2016
    Member
    More actions

    Which 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.

  4. Byron commented on Jul 23, 2016

    @Byron
    Byron
    on Jul 23, 2016
    Member
    More actions

    Closed due to inactivity. Please comment to get the issue reopened.

  5. Byron
    closed this as completedon Jul 23, 2016
  6. barry-scott commented on Jul 25, 2016

    @barry-scott
    barry-scott
    on Jul 25, 2016
    Contributor
    More actions

    Byron,

    Unless you fixed the code this bug is still present in the code base.

    Barry

  7. Byron commented on Jul 30, 2016

    @Byron
    Byron
    on Jul 30, 2016
    Member
    More actions

    @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.

  8. Byron commented on Jul 30, 2016

    @Byron
    Byron
    on Jul 30, 2016
    Member
    More actions

    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.

  9. barry-scott commented on Aug 1, 2016

    @barry-scott
    barry-scott
    on Aug 1, 2016
    Contributor
    More actions

    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 proc

    For 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.

  10. Byron
    reopened this on Aug 2, 2016
  11. Byron
    added
    acknowledged
    and removed
    waiting for feedback
    on Aug 2, 2016
  12. Byron commented on Aug 2, 2016

    @Byron
    Byron
    on Aug 2, 2016
    Member
    More actions

    Thanks @barry-scott, I understand. It seems a context manager for the Cmd object would be an excellent addition to its API.

  13. Byron
    added this to the v2.0.8 - Bugfixes milestone on Aug 2, 2016
  14. Byron
    added
    help wanted
    on Aug 2, 2016
  15. 25 remaining items

  16. ankostis
    added
    waiting for feedback
    and removed
    help wanted
    on Oct 27, 2016
  17. Byron
    modified the milestones: v2.1.1 - Bugfixes, This milestone has been deleted on Dec 8, 2016
  18. Byron
    modified the milestones: This milestone has been deleted, This milestone has been deleted on Mar 8, 2017
  19. Byron commented on Mar 8, 2017

    @Byron
    Byron
    on Mar 8, 2017
    Member
    More actions

    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.

  20. Byron
    closed this as completedon Mar 8, 2017
  21. hobbitten123 commented on Jun 8, 2018

    @hobbitten123
    hobbitten123
    on Jun 8, 2018
    More actions

    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"

  22. Byron commented on Jun 10, 2018

    @Byron
    Byron
    on Jun 10, 2018
    Member
    More actions

    @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.

  23. sevendays commented on May 17, 2019

    @sevendays
    sevendays
    on May 17, 2019
    More actions

    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 invalid
    
    

    The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledgedwaiting for feedback

    Type

    No type

    Projects

    No projects

      Milestone

      • v2.1.4 - Bugfixes

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.