[Twisted-web] spawning a xvfb and firefox with a timeout

Stephan schenette at gmail.com
Fri Aug 19 00:42:03 EDT 2011


I'm attempting to spawn xvfb with firefox using twisted's spawnProcess.

I'm having two issues:

1) when I call a normal process (not xvfb) it seems to
work, but when I call xvfb the process goes defunct

2) perhaps because it goes defunct but the timeout I set in place in
the processprotocol does
not trigger.

==============
here is the code for spawning a process
==============
108         command = ["/usr/bin/xvfb-run", "--auto-servernum",
"/usr/bin/firefox", "-P", profile_id]
109         subprocess = reactor.spawnProcess(TimedProcessProtocol(20),
110                                             command[0], command)
111         logging.debug(type(subprocess))
112         logging.debug("spawned a process: pid: %d", subprocess.pid)
113
114         # this file will be created when firefox starts
115         while (not os.path.exists(self.profile_dir + "/importantfile")):
116             logging.debug("in while loop waiting for
firesharkReady file to exist")
117             pass
118
119         logging.debug("file exist")

==============
here is the process class
==============

 27 class TimedProcessProtocol(protocol.ProcessProtocol):
 28
 29     def __init__(self, timeout):
 30         self.timeout = timeout
 31
 32     def connectionMade(self):
 33         logging.debug("connection made timeout = %d", self.timeout)
 34         @defer.inlineCallbacks
 35         def killIfAlive():
 36             logging.debug("timeout reached - killing process")
 37             try:
 38                 yield self.transport.signalProcess('KILL')
 39             except error.ProcessExitedAlready:
 40                 logging.debug("process already exited")
 41                 pass
 42
 43         d = reactor.callLater(self.timeout, killIfAlive)
 44
 45     def outReceived(self, data):
 46         logging.debug("output: %s", data)
 47
 48     def errReceived(self, data):
 49         logging.debug("errReceived %s", data)



More information about the Twisted-web mailing list