gpg<defunct>pythongnupg.GPG公司

2024-06-09 14:28:10 发布

您现在位置:Python中文网/ 问答频道 /正文

这是在CentOS6上的python2.6下实现的。在

我从python那里得到了不少[gpg]gnupg.GPG公司()多线程情况下的模块。当只有1个线程时,世界似乎还不错,但是如果有更多的线程,那么ps-aefx中的每个python线程下就会显示[gpg]。在

尝试了一些方法来加锁,但我也不相信这有帮助。会不会因为GPG模块是一个调用子进程的包装器,而子进程通常不是线程安全的?在

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

Tags: 模块debugnoneloglockformatdata进程