From 4dc1acfe0fba4215592873d25f9ca8ed61249e6f Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Mon, 13 Jun 2016 12:53:37 +0800 Subject: [PATCH] bug fix Signed-off-by: wwqgtxx --- wwqLyParse/main.py | 4 ++-- wwqLyParse/run.py | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/wwqLyParse/main.py b/wwqLyParse/main.py index c3a4640..0a9e06f 100644 --- a/wwqLyParse/main.py +++ b/wwqLyParse/main.py @@ -183,7 +183,7 @@ def parse(): info=sys.exc_info() result = {"type" : "error","error" : info} jjson = json.dumps(result); - #debug(jjson) + debug(jjson) return jjson @@ -199,7 +199,7 @@ def parseUrl(): info=sys.exc_info() result = {"type" : "error","error" : info} jjson = json.dumps(result); - #debug(jjson) + debug(jjson) return jjson diff --git a/wwqLyParse/run.py b/wwqLyParse/run.py index 89965c3..759f2d6 100644 --- a/wwqLyParse/run.py +++ b/wwqLyParse/run.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # author wwqgtxx -import urllib.request,json,sys,subprocess +import urllib.request,json,sys,subprocess,time import os import socket @@ -27,13 +27,21 @@ def _run_main(): y_bin = bridge.pn(bridge.pjoin(bridge.get_root_path(), './main.py')) py_bin = sys.executable args = [py_bin,'--normal', y_bin] - PIPE = subprocess.PIPE print(args) - p = subprocess.Popen(args, stdout=PIPE, stderr=PIPE, shell=False,cwd=bridge.get_root_path()) + p = subprocess.Popen(args, shell=False,cwd=bridge.get_root_path(),close_fds=True) def init(): - if not IsOpen("127.0.0.1",5000): - return _run_main() + for n in range(3): + if not IsOpen("127.0.0.1",5000): + _run_main() + else: + return + for i in range(5): + if not IsOpen("127.0.0.1",5000): + time.sleep(1+i) + else: + return + raise Exception("can't init server") def closeServer(): if IsOpen("127.0.0.1",5000): @@ -45,6 +53,9 @@ def closeServer(): response = urllib.request.urlopen(req) except: response = None; + +def Cleanup(): + closeServer() def GetVersion(debug=False): if (not debug):