Пример #1
0
def _send():
    while True:
        try:
            try:
                method, arg, cb = _send_q.get()

                proc = gs.attr(PROC_ATTR_NAME)
                if not proc or proc.poll() is not None:
                    if proc:
                        try:
                            proc.kill()
                            proc.stdout.close()
                        except:
                            pass

                    maybe_install()

                    if not gs.checked(DOMAIN, 'launch _recv'):
                        gsq.launch(DOMAIN, _recv)

                    proc, _, err = gsshell.proc([MARGO9_BIN, '-poll=30'],
                                                stderr=gs.LOGFILE,
                                                env={
                                                    'XDG_CONFIG_HOME':
                                                    gs.home_path(),
                                                })
                    gs.set_attr(PROC_ATTR_NAME, proc)

                    if not proc:
                        gs.notice(DOMAIN, 'Cannot MarGo: %s' % err)
                        continue

                    gsq.launch(DOMAIN, lambda: _read_stdout(proc))

                req = Request(f=cb, method=method)
                gs.set_attr(REQUEST_PREFIX + req.token, req)

                gs.debug(
                    DOMAIN, 'margo request: method: %s, token: %s' %
                    (req.method, req.token))

                header, _ = gs.json_encode({
                    'method': method,
                    'token': req.token
                })
                body, _ = gs.json_encode(arg)
                ln = '%s %s\n' % (header, body)
                proc.stdin.write(ln)
            except Exception:
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
Пример #2
0
def _send():
	while True:
		try:
			try:
				method, arg, cb = _send_q.get()

				proc = gs.attr(PROC_ATTR_NAME)
				if not proc or proc.poll() is not None:
					if proc:
						try:
							proc.kill()
							proc.stdout.close()
						except:
							pass

					maybe_install()

					if not gs.checked(DOMAIN, 'launch _recv'):
						gsq.launch(DOMAIN, _recv)

					proc, _, err = gsshell.proc([MARGO9_BIN, '-poll=30'], stderr=gs.LOGFILE ,env={
						'XDG_CONFIG_HOME': gs.home_path(),
					})
					gs.set_attr(PROC_ATTR_NAME, proc)

					if not proc:
						gs.notice(DOMAIN, 'Cannot MarGo: %s' % err)
						continue

					gsq.launch(DOMAIN, lambda: _read_stdout(proc))

				req = Request(f=cb, method=method)
				gs.set_attr(REQUEST_PREFIX+req.token, req)

				gs.debug(DOMAIN, 'margo request: method: %s, token: %s' % (req.method, req.token))

				header, _ = gs.json_encode({'method': method, 'token': req.token})
				body, _ = gs.json_encode(arg)
				ln = '%s %s\n' % (header, body)
				proc.stdin.write(ln)
			except Exception:
				gs.println(gs.traceback())
		except Exception:
			gs.println(gs.traceback())
			break
Пример #3
0
def _send():
    while True:
        try:
            try:
                method, arg, cb = _send_q.get()

                proc = gs.attr(PROC_ATTR_NAME)
                if not proc or proc.poll() is not None:
                    killSrv()
                    maybe_install()

                    if not gs.checked(DOMAIN, "launch _recv"):
                        gsq.launch(DOMAIN, _recv)

                    proc, _, err = gsshell.proc(
                        [MARGO9_BIN, "-poll=30"], stderr=gs.LOGFILE, env={"XDG_CONFIG_HOME": gs.home_path()}
                    )
                    gs.set_attr(PROC_ATTR_NAME, proc)

                    if not proc:
                        gs.notice(DOMAIN, "Cannot start MarGo: %s" % err)
                        try:
                            cb({}, "Abort. Cannot start MarGo")
                        except:
                            pass
                        continue

                    gsq.launch(DOMAIN, lambda: _read_stdout(proc))

                req = Request(f=cb, method=method)
                gs.set_attr(REQUEST_PREFIX + req.token, req)

                gs.debug(DOMAIN, "margo request: method: %s, token: %s" % (req.method, req.token))

                header, _ = gs.json_encode({"method": method, "token": req.token})
                body, _ = gs.json_encode(arg)
                ln = "%s %s\n" % (header, body)
                proc.stdin.write(ln)
            except Exception:
                killSrv()
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
Пример #4
0
def _send():
    while True:
        try:
            try:
                method, arg, cb = _send_q.get()

                proc = gs.attr("mg9.proc")
                if not proc or proc.poll() is not None:
                    if proc:
                        try:
                            proc.kill()
                            proc.stdout.close()
                        except:
                            pass

                    maybe_install()

                    if not gs.checked(DOMAIN, "launch _recv"):
                        gsq.launch(DOMAIN, _recv)

                        # ideally the env should be setup before-hand with a bcall
                        # so we won't run this through the shell
                    proc, _, err = gsshell.proc([MARGO9_BIN], stderr=gs.LOGFILE)
                    gs.set_attr("mg9.proc", proc)

                    if not proc:
                        gs.notice(DOMAIN, "Cannot start MarGo9: %s" % err)
                        continue

                    gsq.launch(DOMAIN, lambda: _read_stdout(proc))

                token = "mg9.autoken.%s" % uuid.uuid4()
                _stash[token] = cb

                header, _ = gs.json_encode({"method": method, "token": token})
                body, _ = gs.json_encode(arg)
                ln = "%s %s\n" % (header, body)
                proc.stdin.write(ln)
            except Exception:
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
Пример #5
0
def _send():
	while True:
		try:
			try:
				method, arg, cb = _send_q.get()

				proc = gs.attr('mg9.proc')
				if not proc or proc.poll() is not None:
					if proc:
						try:
							proc.kill()
							proc.stdout.close()
						except:
							pass

					maybe_install()

					if not gs.checked(DOMAIN, 'launch _recv'):
						gsq.launch(DOMAIN, _recv)

					proc, _, err = gsshell.proc([MARGO9_BIN, '-poll=5'], stderr=gs.LOGFILE)
					gs.set_attr('mg9.proc', proc)

					if not proc:
						gs.notice(DOMAIN, 'Cannot start MarGo9: %s' % err)
						continue

					gsq.launch(DOMAIN, lambda: _read_stdout(proc))

				token = 'mg9.autoken.%s' % uuid.uuid4()
				_stash[token] = cb

				header, _ = gs.json_encode({'method': method, 'token': token})
				body, _ = gs.json_encode(arg)
				ln = '%s %s\n' % (header, body)
				proc.stdin.write(ln)
			except Exception:
				gs.println(gs.traceback())
		except Exception:
			gs.println(gs.traceback())
			break