Пример #1
0
def system(path, cmd, args):
    from eventlet.processes import Process
    print ">", path, cmd, " ".join(args)
    curdir = os.path.abspath(os.curdir)
    os.chdir(path)
    p = Process(cmd, args)
    result = p.wait()
    content = p.read()
    os.chdir(curdir)
    print content
    return result, content
Пример #2
0
def wrap_module(fqname, dead_callback = None):
    """
@brief wrap a module in another process through a saranwrap proxy
@param fqname The fully qualified name of the module.
@param dead_callback A callable to invoke if the process exits."""
    pythonpath_sync()
    global _g_debug_mode
    if _g_debug_mode:
        p = Process('python', [__file__, '--module', fqname, '--logfile', '/tmp/saranwrap.log'], dead_callback)
    else:
        p = Process('python', [__file__, '--module', fqname,], dead_callback)
    prox = Proxy(p, p)
    return prox
Пример #3
0
    def __init__(self, label='bithorded', bithorded=os.environ.get('BITHORDED', 'bithorded'), config={}):
        if hasattr(config, 'setdefault'):
            suffix = (time(), os.getpid())
            server_cfg = config.setdefault('server', {})
            server_cfg.setdefault('tcpPort', 0)
            server_cfg.setdefault('inspectPort', 0)
            server_cfg.setdefault('unixSocket', "bhtest-sock-%d-%d" % suffix)
            cache_cfg = config.setdefault('cache', {})
            if not cache_cfg.get('dir'):
                d = 'bhtest-cache-%d-%d' % suffix
                os.mkdir(d)
                cache_cfg['dir'] = d

        self.config = config
        self.label = label
        self.started = False
        self.queue = eventlet.Queue()
        Process.__init__(self, 'stdbuf', ['-o0', '-e0', bithorded, '-c', '/dev/stdin'])
Пример #4
0
 def run(self):
     Process.run(self)
     atexit.register(self.kill)
     def gen_config(value, key=[]):
         if hasattr(value, 'iteritems'):
             return "\n".join(gen_config(value, key+[ikey]) for ikey, value in value.iteritems())
         elif key:
             return "%s=%s" % ('.'.join(key), value)
         else:
             return value
     self.write(gen_config(self.config))
     self.close_stdin()
     for line in self.child_stdout_stderr:
         if self.label:
             print "%s: %s" % (self.label, line.rstrip())
         if line.find('Server started') >= 0:
             self.started = True
             break
     assert self.started
     eventlet.spawn(self._run)
Пример #5
0
def wrap(obj, dead_callback=None):
    """
    wrap in object in another process through a saranwrap proxy
    :param object: The object to wrap.
    :dead_callback: A callable to invoke if the process exits.
    """

    if type(obj).__name__ == 'module':
        return wrap_module(obj.__name__, dead_callback)
    pythonpath_sync()
    if _g_debug_mode:
        p = Process(sys.executable, [
            "-W", "ignore", __file__, '--child', '--logfile',
            os.path.join(tempfile.gettempdir(), 'saranwrap.log')
        ], dead_callback)
    else:
        p = Process(sys.executable, ["-W", "ignore", __file__, '--child'],
                    dead_callback)
    prox = Proxy(ChildProcess(p, p))
    prox.obj = obj
    return prox.obj
Пример #6
0
def wrap(obj, dead_callback = None):
    """
@brief wrap in object in another process through a saranwrap proxy
@param object The object to wrap.
@param dead_callback A callable to invoke if the process exits."""

    if type(obj).__name__ == 'module':
        return wrap_module(obj.__name__, dead_callback)
    pythonpath_sync()
    p = Process('python', [__file__, '--child'], dead_callback)
    prox = Proxy(p, p)
    prox.obj = obj
    return prox.obj
Пример #7
0
def wrap_module(fqname, dead_callback=None):
    """
    wrap a module in another process through a saranwrap proxy

    :param fqname: The fully qualified name of the module.
    :param dead_callback: A callable to invoke if the process exits.
    """
    pythonpath_sync()
    global _g_debug_mode
    if _g_debug_mode:
        p = Process(sys.executable, [
            "-W", "ignore", __file__, '--module', fqname, '--logfile',
            os.path.join(tempfile.gettempdir(), 'saranwrap.log')
        ], dead_callback)
    else:
        p = Process(sys.executable, [
            "-W",
            "ignore",
            __file__,
            '--module',
            fqname,
        ], dead_callback)
    prox = Proxy(ChildProcess(p, p))
    return prox