未验证 提交 aebaffd2 编写于 作者: 走神的阿圆's avatar 走神的阿圆 提交者: GitHub

Pb check and update. (#630)

上级 951dcbd3
......@@ -27,6 +27,7 @@ import webbrowser
import requests
from visualdl.reader.reader import LogReader
from argparse import ArgumentParser
from visualdl.utils import update_util
from flask import (Flask, Response, redirect, request, send_file, send_from_directory)
from flask_babel import Babel
......@@ -153,7 +154,7 @@ def gen_result(status, msg, data):
return result
def create_app(args):
def create_app(args, method):
app = Flask(__name__, static_url_path="")
# set static expires in a short time to reduce browser's memory usage.
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 30
......@@ -165,6 +166,7 @@ def create_app(args):
# use a memory cache to reduce disk reading frequency.
CACHE = MemCache(timeout=args.cache_timeout)
cache_get = lib.cache_get(CACHE)
update_util.PbUpdater(method).start()
public_path = args.public_path.rstrip('/')
api_path = public_path + '/api'
......@@ -348,7 +350,7 @@ def _run(logdir,
language=language,
public_path=public_path)
logger.info(" port=" + str(args.port))
app = create_app(args)
app = create_app(args, 'run')
index_url = "http://" + host + ":" + str(port) + args.public_path
if open_browser:
threading.Thread(
......@@ -399,7 +401,7 @@ def main():
for sig in [signal.SIGINT, signal.SIGHUP, signal.SIGTERM]:
signal.signal(sig, clean_template)
logger.info(" port=" + str(args.port))
app = create_app(args=args)
app = create_app(args, 'main')
app.run(debug=False, host=args.host, port=args.port, threaded=False)
......
# Copyright (c) 2020 VisualDL Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =======================================================================
import threading
import hashlib
import requests
import json
from visualdl import __version__
from visualdl.proto.record_pb2 import DESCRIPTOR
def md5(text):
if isinstance(text, str):
text = text.encode("utf8")
md5 = hashlib.md5()
md5.update(text)
return md5.hexdigest()
class PbUpdater(threading.Thread):
def __init__(self, start_method):
threading.Thread.__init__(self)
self.start_method = start_method
def update_pb(self,
start_method,
version=__version__,
md5_code=md5(str(DESCRIPTOR))
):
payload = {
"data": {
"start_method": start_method,
"version": version,
"md5": md5_code
}
}
url = 'https://paddlepaddle.org.cn/paddlehub/stat?from=vdl'
try:
r = requests.post(url=url, json=json.dumps(payload, sort_keys=True))
if r.json().get("update_flag", 0) == 1:
pb_bin = r.json().get("pb_bin")
with open('/visualdl/proto/record_pb2.py', mode='wb') as fp:
fp.write(pb_bin)
print('Update pb file successfully.')
except Exception as err:
pass
def run(self):
self.update_pb(start_method=self.start_method,
version=__version__,
md5_code=md5(str(DESCRIPTOR))
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册