def restart_with_reloader(error_func=None):
    to_mon = []
    while 1:
        _log('info', ' * Clastic restarting with reloader')
        args = [sys.executable] + sys.argv
        new_environ = os.environ.copy()
        new_environ['WERKZEUG_RUN_MAIN'] = 'true'
        if os.name == 'nt':
            for key, value in new_environ.iteritems():
                if isinstance(value, unicode):
                    new_environ[key] = value.encode('iso-8859-1')
        child_proc = subprocess.Popen(args,
                                      env=new_environ,
                                      stderr=subprocess.PIPE)
        stderr_buff = deque(maxlen=_STDERR_BUFF_SIZE)

        def consume_lines():
            for line in iter(child_proc.stderr.readline, ''):
                if line.startswith(_MON_PREFIX):
                    to_mon[:] = literal_eval(line[len(_MON_PREFIX):])
                else:
                    sys.stderr.write(line)
                    stderr_buff.append(line)

        while child_proc.poll() is None:
            consume_lines()
        consume_lines()

        exit_code = child_proc.returncode
        if exit_code == 3:
            continue
        elif error_func and exit_code == 1 and stderr_buff:
            enable_tty_echo()
            tb_str = ''.join(stderr_buff)
            err_server = error_func(tb_str, to_mon)
            try:
                reloader_loop(to_mon, 1)
            except __HOLE__:
                return 0
            except SystemExit as se:
                if se.code == 3:
                    continue
                return se.code
            finally:
                err_server.shutdown()
                err_server.server_close()
            return 0
        else:
            return exit_code
dataset/ETHPy150Open mahmoud/clastic/clastic/server.py/restart_with_reloader