1

This is under python 2.6 on CentOS6.

I am getting quite a bit of [gpg] from python's gnupg.GPG() module in a multi-threaded situation. The world seems to be fine when there is only 1 thread, but having more would start showing [gpg] under each python thread from ps -aefx.

Tried a few thing in adding a lock, but I don't believe that help either. Would that because GPG module is a wrapper calling subprocess, and subproces generally is not threadsafe?

GPG_LOCK = threading.LOCK()

def decrypt(s):
  LOG.debug("decrpting: {0}".format(s))
  d = None
  try:
    GPG_LOCK.acquire()
    gpg = gnupg.GPG(binary='/usr/bin/gpg',homedir='/gpgkeys',verbose='advanced')
    d = gpg.decrypt(s)
    LOG.debug("decrypted string: {0}".format(d.data))
    LOG.debug("decrupted error: {0}".format(d.stderr))
  except Exception as e:
    LOG.error(e)
    traceback.print_exc()
  finally:
    GPG_LOCK.release()
  return d.data if d else None
Hoi Tsang
  • 31
  • 1
  • 2
  • I don't understand your issue. The application GnuPG may well be called multiple times in parallel and takes care of locking with respect to data maintained by GnuPG. Are you getting any error messages, having other issues? Can you provide a minimal runnable example to reproduce the issue? – Jens Erat Nov 04 '16 at 15:22
  • That's what I thought as well, having a lock that should take care of concurrency. However I don't believe it's the cause. Given the GPG module is wrapping the subprocess call... most likely it's the subprocess call hanging around.... This post gave some clue on how subprocess create zombie... http://stackoverflow.com/questions/2760652/how-to-kill-or-avoid-zombie-processes-with-subprocess-module – Hoi Tsang Nov 04 '16 at 20:10

0 Answers0