aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/scripts/uzbl-tabbed
diff options
context:
space:
mode:
authorGravatar Dmytro Milinevskyy <milinevskyy@gmail.com>2010-03-21 23:57:02 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2010-03-22 00:03:04 +0800
commit08f69b7c7f650248cf146c95eb845ecd07051155 (patch)
tree36b28545e32232ccab78c5e659880d78c1bacad0 /examples/data/scripts/uzbl-tabbed
parentb71759700d5cc0695d47a43b7257c5b66f91ff8c (diff)
Use SIGCHLD signal handler to clean up child zombie processes.
Diffstat (limited to 'examples/data/scripts/uzbl-tabbed')
-rwxr-xr-xexamples/data/scripts/uzbl-tabbed33
1 files changed, 16 insertions, 17 deletions
diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed
index 160c562..1597dd3 100755
--- a/examples/data/scripts/uzbl-tabbed
+++ b/examples/data/scripts/uzbl-tabbed
@@ -158,7 +158,7 @@ import atexit
import types
from gobject import io_add_watch, source_remove, timeout_add, IO_IN, IO_HUP
-from signal import signal, SIGTERM, SIGINT
+from signal import signal, SIGTERM, SIGINT, SIGCHLD
from optparse import OptionParser, OptionGroup
from traceback import print_exc
@@ -368,9 +368,8 @@ class SocketClient:
class UzblInstance:
'''Uzbl instance meta-data/meta-action object.'''
- def __init__(self, parent, tab, name, uri, title, switch, process):
+ def __init__(self, parent, tab, name, uri, title, switch):
- self.process = process
self.parent = parent
self.tab = tab
self.name = name
@@ -527,18 +526,6 @@ class UzblInstance:
self._client.close()
self._client = None
- pid = self.process.pid
- timeout = time.time() + 5
-
- while self.process.poll() is None and time.time() < timeout:
- # Sleep between polls.
- time.sleep(0.1)
-
- if self.process.poll() is None:
- # uzbl instance didn't exit in time.
- error("quit timeout expired, sending SIGTERM to uzbl instance")
- self.process.terminate()
-
class UzblTabbed:
'''A tabbed version of uzbl using gtk.Notebook'''
@@ -549,6 +536,7 @@ class UzblTabbed:
self._timers = {}
self._buffer = ""
self._killed = False
+ self._processes = []
# A list of the recently closed tabs
self._closed = []
@@ -667,6 +655,9 @@ class UzblTabbed:
# Catch keyboard interrupts
signal(SIGINT, lambda signum, stack_frame: self.terminate(SIGINT))
+ # Catch SIGCHLD
+ signal(SIGCHLD, lambda signum, stack_frame: self.join_children())
+
try:
gtk.main()
@@ -687,6 +678,14 @@ class UzblTabbed:
raise
+ def join_children(self):
+ '''Find and remove zombie children processes.'''
+
+ for p in self._processes:
+ if p.poll() is not None:
+ self._processes.remove(p)
+
+
def terminate(self, termsig=None):
'''Handle termination signals and exit safely and cleanly.'''
@@ -1008,9 +1007,9 @@ class UzblTabbed:
cmd = ['uzbl-browser', '-n', name, '-s', str(sid),
'--connect-socket', self.socket_path, '--uri', uri]
- process = subprocess.Popen(cmd) # TODO: do i need close_fds=True ?
+ self._processes += [subprocess.Popen(cmd)] # TODO: do i need close_fds=True ?
- uzbl = UzblInstance(self, tab, name, uri, title, switch, process)
+ uzbl = UzblInstance(self, tab, name, uri, title, switch)
SocketClient.instances_queue[name] = uzbl
self.tabs[tab] = uzbl