Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
c428a899
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c428a899
编写于
6月 16, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add main server
上级
8c7956ba
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
48 addition
and
69 deletion
+48
-69
python/paddle_serving_client/__init__.py
python/paddle_serving_client/__init__.py
+17
-0
python/paddle_serving_server/__init__.py
python/paddle_serving_server/__init__.py
+0
-31
python/paddle_serving_server/serve.py
python/paddle_serving_server/serve.py
+31
-38
未找到文件。
python/paddle_serving_client/__init__.py
浏览文件 @
c428a899
...
...
@@ -190,6 +190,22 @@ class Client(object):
else
:
self
.
rpc_timeout_ms
=
rpc_timeout
def
get_serving_port
(
self
,
endpoints
):
import
requests
import
json
req
=
json
.
dumps
({})
r
=
requests
.
post
(
"http://"
+
endpoints
[
0
],
req
)
result
=
r
.
json
()
print
(
result
)
if
"endpoint_list"
not
in
result
:
raise
ValueError
(
"server not ready"
)
else
:
endpoints
=
[
endpoints
[
0
].
split
(
":"
)[
0
]
+
":"
+
str
(
result
[
"endpoint_list"
][
0
])
]
return
endpoints
def
connect
(
self
,
endpoints
=
None
):
# check whether current endpoint is available
# init from client config
...
...
@@ -200,6 +216,7 @@ class Client(object):
"You must set the endpoints parameter or use add_variant function to create a variant."
)
else
:
endpoints
=
self
.
get_serving_port
(
endpoints
)
if
self
.
predictor_sdk_
is
None
:
self
.
add_variant
(
'default_tag_{}'
.
format
(
id
(
self
)),
endpoints
,
100
)
...
...
python/paddle_serving_server/__init__.py
浏览文件 @
c428a899
...
...
@@ -593,34 +593,3 @@ class MultiLangServer(object):
server
.
start
()
p_bserver
.
join
()
server
.
wait_for_termination
()
from
BaseHTTPServer
import
BaseHTTPRequestHandler
import
urllib
import
json
from
.serve
import
start_standard_model
import
subprocess
class
MainService
(
BaseHTTPRequestHandler
):
def
_set_headers
(
self
):
self
.
send_response
(
200
)
self
.
send_header
(
'Content-type'
,
'application/json'
)
self
.
end_headers
()
def
do_GET
(
self
):
response
=
{
'status'
:
'SUCCESS'
,
'data'
:
'hello from server'
}
self
.
_set_headers
()
self
.
wfile
.
write
(
json
.
dumps
(
response
))
def
do_POST
(
self
):
path
=
self
.
path
print
(
path
)
content_length
=
int
(
self
.
headers
[
'Content-Length'
])
post_data
=
self
.
rfile
.
read
(
content_length
)
print
(
post_data
)
p
=
subprocess
.
popen
(
start_standard_model
)
response
=
{
"endpoint_list"
:
[
"9292"
]}
self
.
_set_headers
()
self
.
wfile
.
write
(
json
.
dumps
(
response
))
python/paddle_serving_server/serve.py
浏览文件 @
c428a899
...
...
@@ -18,8 +18,11 @@ Usage:
python -m paddle_serving_server.serve --model ./serving_server_model --port 9292
"""
import
argparse
from
.
web_service
import
WebService
from
web_service
import
WebService
from
flask
import
Flask
,
request
from
BaseHTTPServer
import
BaseHTTPRequestHandler
,
HTTPServer
import
json
import
subprocess
def
parse_args
():
# pylint: disable=doc-string-missing
...
...
@@ -97,44 +100,9 @@ def start_standard_model(): # pylint: disable=doc-string-missing
server
.
run_server
()
from
BaseHTTPServer
import
BaseHTTPRequestHandler
,
HTTPServer
import
urllib
import
json
import
subprocess
class
MainService
(
BaseHTTPRequestHandler
):
def
_set_headers
(
self
):
self
.
send_response
(
200
)
self
.
send_header
(
'Content-type'
,
'application/json'
)
self
.
end_headers
()
def
do_GET
(
self
):
response
=
{
'status'
:
'SUCCESS'
,
'data'
:
'hello from server'
}
self
.
_set_headers
()
self
.
wfile
.
write
(
json
.
dumps
(
response
))
def
do_POST
(
self
):
path
=
self
.
path
print
(
path
)
content_length
=
int
(
self
.
headers
[
'Content-Length'
])
post_data
=
self
.
rfile
.
read
(
content_length
)
print
(
post_data
)
p
=
subprocess
.
popen
(
start_standard_model
)
response
=
{
"endpoint_list"
:
[
"9292"
]}
self
.
_set_headers
()
self
.
wfile
.
write
(
json
.
dumps
(
response
))
if
__name__
==
"__main__"
:
args
=
parse_args
()
def
start_serving
():
if
args
.
name
==
"None"
:
#start_standard_model()
server
=
HTTPServer
((
''
,
int
(
args
.
port
)),
MainService
)
server
.
serve_forever
()
start_standard_model
()
else
:
service
=
WebService
(
name
=
args
.
name
)
service
.
load_model_config
(
args
.
model
)
...
...
@@ -158,3 +126,28 @@ if __name__ == "__main__":
port
=
service
.
port
,
threaded
=
False
,
processes
=
4
)
class
MainService
(
BaseHTTPRequestHandler
):
def
do_POST
(
self
):
content_length
=
int
(
self
.
headers
[
'Content-Length'
])
post_data
=
self
.
rfile
.
read
(
content_length
)
#p = subprocess.Popen(start_serving())
from
multiprocessing
import
Pool
pool
=
Pool
(
3
)
pool
.
apply_async
(
start_serving
)
if
1
:
response
=
{
"endpoint_list"
:
[
args
.
port
]}
else
:
response
=
{
"message"
:
"start serving failed"
}
self
.
send_response
(
200
)
self
.
send_header
(
'Content-type'
,
'application/json'
)
self
.
end_headers
()
self
.
wfile
.
write
(
json
.
dumps
(
response
))
if
__name__
==
"__main__"
:
args
=
parse_args
()
server
=
HTTPServer
((
'localhost'
,
8080
),
MainService
)
print
(
'Starting server, use <Ctrl-C> to stop'
)
server
.
serve_forever
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录