

import os
import subprocess


def git_suffix(fname):
    """
    :returns: `<short git hash>` if Git repository found
    """
    try:
        po = subprocess.Popen(
            ['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE,
            stderr=open(os.devnull, 'w'), cwd=os.path.dirname(fname))
        return "-git" + po.stdout.read().strip()
    except:
        # trapping everything on purpose; git may not be installed or it
        # may not work properly
        return ''



import os
import subprocess


def git_suffix(fname):
    """
    :returns: `<short git hash>` if Git repository found
    """
    try:
        po = subprocess.check_output(
            ['git', 'rev-parse', '--short', 'HEAD'],
            cwd=os.path.dirname(fname))
        return "-git" + po.stdout.read().strip()
    except:
        # trapping everything on purpose; git may not be installed or it
        # may not work properly
        return ''

Replace subprocess.Popen with check_output to avoid git zombies
Replace subprocess.Popen with check_output to avoid git zombies

  
  
  import os
  import subprocess
  
  
  def git_suffix(fname):
      """
      :returns: `<short git hash>` if Git repository found
      """
      try:
-         po = subprocess.Popen(
+         po = subprocess.check_output(
-             ['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE,
+             ['git', 'rev-parse', '--short', 'HEAD'],
-             stderr=open(os.devnull, 'w'), cwd=os.path.dirname(fname))
+             cwd=os.path.dirname(fname))
          return "-git" + po.stdout.read().strip()
      except:
          # trapping everything on purpose; git may not be installed or it
          # may not work properly
          return ''
  
Replace subprocess.Popen with check_output to avoid git zombies
## Code Before:


import os
import subprocess


def git_suffix(fname):
    """
    :returns: `<short git hash>` if Git repository found
    """
    try:
        po = subprocess.Popen(
            ['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE,
            stderr=open(os.devnull, 'w'), cwd=os.path.dirname(fname))
        return "-git" + po.stdout.read().strip()
    except:
        # trapping everything on purpose; git may not be installed or it
        # may not work properly
        return ''

## Instruction:
Replace subprocess.Popen with check_output to avoid git zombies
## Code After:


import os
import subprocess


def git_suffix(fname):
    """
    :returns: `<short git hash>` if Git repository found
    """
    try:
        po = subprocess.check_output(
            ['git', 'rev-parse', '--short', 'HEAD'],
            cwd=os.path.dirname(fname))
        return "-git" + po.stdout.read().strip()
    except:
        # trapping everything on purpose; git may not be installed or it
        # may not work properly
        return ''
