~dobey/ubuntuone-client/fix-test-fails

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/tunnel_runner.py

  • Committer: Tarmac
  • Author(s): Alejandro J. Cura
  • Date: 2012-03-27 13:19:39 UTC
  • mfrom: (1214.2.2 stop-proxy-tunnel)
  • Revision ID: tarmac-20120327131939-qlahrj8rjwk9ar1o
- Stop the proxy tunnel when stopping the reactor (LP: #963485).

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    def __init__(self, host, port):
34
34
        """Start this runner instance."""
35
35
        self.client_d = defer.Deferred()
 
36
        self.process_transport = None
36
37
        try:
37
38
            self.start_process(host, port)
38
39
        except ImportError:
45
46
        protocol = TunnelProcessProtocol(self.client_d)
46
47
        process_path = self.get_process_path()
47
48
        args = [TUNNEL_EXECUTABLE, host, str(port)]
48
 
        reactor.spawnProcess(protocol, process_path, env=None, args=args)
 
49
        self.process_transport = reactor.spawnProcess(protocol, process_path,
 
50
                                                      env=None, args=args)
 
51
        reactor.addSystemEventTrigger("before", "shutdown", self.stop)
 
52
 
 
53
    def stop(self):
 
54
        """Stop the tunnel process if still running."""
 
55
        logger.info("Stopping process %r", self.process_transport.pid)
 
56
        if self.process_transport.pid is not None:
 
57
            self.process_transport.signalProcess("KILL")
49
58
 
50
59
    def get_process_path(self):
51
60
        """Get the path to the tunnel process."""