~ubuntu-branches/ubuntu/raring/duplicity/raring-updates

« back to all changes in this revision

Viewing changes to src/GnuPGInterface.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Terry
  • Date: 2011-04-03 20:40:34 UTC
  • mfrom: (1.9.1 upstream) (16.2.6 natty)
  • Revision ID: james.westby@ubuntu.com-20110403204034-5m1eri4z5qr0nyrr
Tags: 0.6.13-0ubuntu1
* Resync with Debian, no remaining changes
* New upstream release
  - silent data corruption with checkpoint/restore (LP: #613244)
  - Assertion error "time not moving forward at appropriate pace"
    (LP: #579958)
* debian/patches/04future.dpatch:
  - Dropped, applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
224
224
import sys
225
225
import fcntl
226
226
 
227
 
from duplicity import log
228
 
 
229
 
try:
230
 
    import threading
231
 
except ImportError:
232
 
    import dummy_threading
233
 
    log.Warn("Threading not available -- zombie processes may appear")
234
 
 
235
227
__author__   = "Frank J. Tobin, ftobin@neverending.org"
236
228
__version__  = "0.3.2"
237
229
__revision__ = "$Id: GnuPGInterface.py,v 1.6 2009/06/06 17:35:19 loafman Exp $"
405
397
            process._pipes[fh_name] = Pipe(fh.fileno(), fh.fileno(), 1)
406
398
 
407
399
        process.pid = os.fork()
408
 
        if process.pid != 0:
409
 
            # start a threaded_waitpid on the child
410
 
            process.thread = threading.Thread(target=threaded_waitpid,
411
 
                                              name="wait%d" % process.pid,
412
 
                                              args=(process,))
413
 
            process.thread.start()
414
400
 
415
401
        if process.pid == 0: self._as_child(process, gnupg_commands, args)
416
402
        return self._as_parent(process)
639
625
    """
640
626
 
641
627
    def __init__(self):
642
 
        self._pipes   = {}
643
 
        self.handles  = {}
644
 
        self.pid      = None
645
 
        self._waited  = None
646
 
        self.thread   = None
647
 
        self.returned = None
 
628
        self._pipes  = {}
 
629
        self.handles = {}
 
630
        self.pid     = None
 
631
        self._waited = None
648
632
 
649
633
    def wait(self):
650
 
        """
651
 
        Wait on threaded_waitpid to exit and examine results.
652
 
        Will raise an IOError if the process exits non-zero.
653
 
        """
654
 
        if self.returned == None:
655
 
            self.thread.join()
656
 
        if self.returned != 0:
657
 
            raise IOError, "GnuPG exited non-zero, with code %d" % (self.returned >> 8)
658
 
 
659
 
 
660
 
def threaded_waitpid(process):
661
 
    """
662
 
    When started as a thread with the Process object, thread
663
 
    will execute an immediate waitpid() against the process
664
 
    pid and will collect the process termination info.  This
665
 
    will allow us to reap child processes as soon as possible,
666
 
    thus freeing resources quickly.
667
 
    """
668
 
    try:
669
 
        process.returned = os.waitpid(process.pid, 0)[1]
670
 
    except:
671
 
        log.Debug("GPG process %d terminated before wait()" % process.pid)
672
 
        process.returned = 0
673
 
 
 
634
        """Wait on the process to exit, allowing for child cleanup.
 
635
        Will raise an IOError if the process exits non-zero."""
 
636
 
 
637
        e = os.waitpid(self.pid, 0)[1]
 
638
        if e != 0:
 
639
            raise IOError, "GnuPG exited non-zero, with code %d" % (e >> 8)
674
640
 
675
641
def _run_doctests():
676
 
    import doctest, GnuPGInterface
 
642
    import doctest, GnuPGInterface #@UnresolvedImport
677
643
    return doctest.testmod(GnuPGInterface)
678
644
 
679
645
# deprecated