提交 3802c07c 编写于 作者: 走神的阿圆's avatar 走神的阿圆

Add hub_name

上级 84c33d73
...@@ -25,7 +25,6 @@ import re ...@@ -25,7 +25,6 @@ import re
from paddlehub.commands.base_command import BaseCommand, ENTRY from paddlehub.commands.base_command import BaseCommand, ENTRY
from paddlehub.common.dir import CONF_HOME from paddlehub.common.dir import CONF_HOME
from paddlehub.common.server_config import default_server_config from paddlehub.common.server_config import default_server_config
from paddlehub.common.hub_server import CacheUpdater
from paddlehub.common.hub_server import HubServer from paddlehub.common.hub_server import HubServer
HubServer() HubServer()
...@@ -102,7 +101,6 @@ class ConfigCommand(BaseCommand): ...@@ -102,7 +101,6 @@ class ConfigCommand(BaseCommand):
print(str) print(str)
def execute(self, argv): def execute(self, argv):
CacheUpdater("hub_config").start()
args = self.parser.parse_args() args = self.parser.parse_args()
if args.option is None: if args.option is None:
ConfigCommand.show_config() ConfigCommand.show_config()
......
...@@ -239,8 +239,7 @@ class ServingCommand(BaseCommand): ...@@ -239,8 +239,7 @@ class ServingCommand(BaseCommand):
StandaloneApplication( StandaloneApplication(
app.create_app(init_flag=False, configs=configs), options).run() app.create_app(init_flag=False, configs=configs), options).run()
@staticmethod def start_single_app_with_file(self, configs):
def start_single_app_with_file(configs):
use_gpu = configs.get("use_gpu", False) use_gpu = configs.get("use_gpu", False)
port = configs.get("port", 8866) port = configs.get("port", 8866)
if ServingCommand.is_port_occupied("127.0.0.1", port) is True: if ServingCommand.is_port_occupied("127.0.0.1", port) is True:
...@@ -251,6 +250,7 @@ class ServingCommand(BaseCommand): ...@@ -251,6 +250,7 @@ class ServingCommand(BaseCommand):
module_info = ServingCommand.preinstall_modules(module) module_info = ServingCommand.preinstall_modules(module)
for index in range(len(module_info)): for index in range(len(module_info)):
configs[index].update(module_info[index]) configs[index].update(module_info[index])
self.dump_pid_file()
app.run(use_gpu, configs=configs, port=port) app.run(use_gpu, configs=configs, port=port)
@staticmethod @staticmethod
...@@ -304,6 +304,7 @@ class ServingCommand(BaseCommand): ...@@ -304,6 +304,7 @@ class ServingCommand(BaseCommand):
"queue_size": 20 "queue_size": 20
}) for item in module_info }) for item in module_info
] ]
self.dump_pid_file()
app.run(use_gpu, configs=module_info, port=port) app.run(use_gpu, configs=module_info, port=port)
else: else:
print("Lack of necessary parameters!") print("Lack of necessary parameters!")
......
...@@ -33,7 +33,7 @@ from paddlehub.common.server_config import default_server_config ...@@ -33,7 +33,7 @@ from paddlehub.common.server_config import default_server_config
from paddlehub.io.parser import yaml_parser from paddlehub.io.parser import yaml_parser
from paddlehub.common.lock import lock from paddlehub.common.lock import lock
from paddlehub.common.dir import CONF_HOME, CACHE_HOME from paddlehub.common.dir import CONF_HOME, CACHE_HOME
from paddlehub.common.utils import ConfigInfo from paddlehub.common.srv_utils import ConfigInfo
RESOURCE_LIST_FILE = "resource_list_file.yml" RESOURCE_LIST_FILE = "resource_list_file.yml"
CACHE_TIME = 60 * 10 CACHE_TIME = 60 * 10
......
...@@ -11,14 +11,17 @@ ...@@ -11,14 +11,17 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from paddlehub.common.utils import ConfigInfo import time
import uuid
from paddlehub.common.utils import md5
HUB_SERVERS = ["http://paddlepaddle.org.cn/paddlehub"] HUB_SERVERS = ["http://paddlepaddle.org.cn/paddlehub"]
hub_name = md5(str(uuid.uuid1())[-12:]) + "-" + str(int(time.time()))
default_server_config = { default_server_config = {
"server_url": HUB_SERVERS, "server_url": HUB_SERVERS,
"resource_storage_server_url": "https://bj.bcebos.com/paddlehub-data/", "resource_storage_server_url": "https://bj.bcebos.com/paddlehub-data/",
"debug": False, "debug": False,
"log_level": "DEBUG", "log_level": "DEBUG",
"hub_name": ConfigInfo().get_hub_name() "hub_name": hub_name
} }
...@@ -15,8 +15,15 @@ ...@@ -15,8 +15,15 @@
import requests import requests
import paddle import paddle
import json import json
import time
import uuid
import os
from paddlehub import version from paddlehub import version
from paddlehub.common.dir import CONF_HOME
from paddlehub.common.decorator_utils import singleton
from paddlehub.common.utils import md5
from paddlehub.common.server_config import default_server_config
def uri_path(server_url, api): def uri_path(server_url, api):
...@@ -37,3 +44,24 @@ def hub_request(api, params, extra=None, timeout=8): ...@@ -37,3 +44,24 @@ def hub_request(api, params, extra=None, timeout=8):
params["extra"] = json.dumps(extra) params["extra"] = json.dumps(extra)
r = requests.get(api, params, timeout=timeout) r = requests.get(api, params, timeout=timeout)
return r.json() return r.json()
@singleton
class ConfigInfo(object):
def __init__(self):
self.filepath = os.path.join(CONF_HOME, "config.json")
self.hub_name = None
self.configs = None
if os.path.exists(self.filepath):
with open(self.filepath, "r") as fp:
self.configs = json.load(fp)
self.hub_name = self.configs.get("hub_name", None)
def get_hub_name(self):
if self.hub_name is None:
self.hub_name = md5(str(uuid.uuid1())[-12:]) + "-" + str(
int(time.time()))
with open(self.filepath, "w") as fp:
fp.write(json.dumps(default_server_config))
return self.hub_name
...@@ -22,16 +22,12 @@ import os ...@@ -22,16 +22,12 @@ import os
import multiprocessing import multiprocessing
import hashlib import hashlib
import platform import platform
import uuid
import json
import paddle.fluid as fluid import paddle.fluid as fluid
import six import six
from paddlehub.module import module_desc_pb2 from paddlehub.module import module_desc_pb2
from paddlehub.common.logger import logger from paddlehub.common.logger import logger
from paddlehub.common.dir import CONF_HOME
from paddlehub.common.decorator_utils import singleton
def version_compare(version1, version2): def version_compare(version1, version2):
...@@ -59,24 +55,6 @@ def get_platform(): ...@@ -59,24 +55,6 @@ def get_platform():
return platform.platform() return platform.platform()
@singleton
class ConfigInfo(object):
def __init__(self):
self.filepath = os.path.join(CONF_HOME, "config.json")
self.hub_name = None
self.configs = None
if os.path.exists(self.filepath):
with open(self.filepath, "r") as fp:
self.configs = json.load(fp)
self.use_id = self.configs.get("hub_name", None)
def get_hub_name(self):
if self.hub_name is None:
hub_name = uuid.UUID(int=uuid.getnode()).hex[-12:]
self.hub_name = md5(hub_name)
return self.hub_name
def is_windows(): def is_windows():
return get_platform().lower().startswith("windows") return get_platform().lower().startswith("windows")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册