'Register some hooks into the subcommand modules that allow us
to properly clean up self.hosts created in forked subprocesses.'

def _register_subcommand_hooks(self):

    def on_fork(cmd):
        self._existing_hosts_on_fork = set(self.hosts)
    def on_join(cmd):
        new_hosts = (self.hosts - self._existing_hosts_on_fork)
        for host in new_hosts:
            host.close()
    subcommand.subcommand.register_fork_hook(on_fork)
    subcommand.subcommand.register_join_hook(on_join)
