Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
bom_identify
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e1f97998
authored
Jun 04, 2020
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
临时增加http服务
parent
ebf97191
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
0 deletions
http_server.py
id_server.py
http_server.py
0 → 100644
View file @
e1f97998
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import
json
from
urllib.parse
import
quote
import
tornado.web
import
tornado.ioloop
import
traceback
from
utils.config
import
model_config
from
predic_fac
import
PredictorFac
from
utils.log_manager
import
get_logger
log_server
=
get_logger
(
'httpserver'
)
class
BaseHandler
(
tornado
.
web
.
RequestHandler
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
log_server
.
info
(
'http server start!'
)
self
.
predictorfac
=
PredictorFac
(
model_config
)
class
KwHandler
(
BaseHandler
):
async
def
get
(
self
):
target
=
quote
(
self
.
get_argument
(
'keyword'
))
res
=
self
.
predictorfac
.
predict
(
target
)
res
[
'status'
]
=
1
self
.
write
(
res
)
class
DictHandler
(
BaseHandler
):
async
def
post
(
self
):
try
:
dic_data
=
json
.
loads
(
self
.
request
.
body
)
res
=
self
.
predictorfac
.
predict
(
dic_data
)
res
[
'status'
]
=
1
except
json
.
decoder
.
JSONDecodeError
:
res
=
self
.
predictorfac
.
predict
(
self
.
request
.
body
)
res
[
'status'
]
=
1
except
:
res
=
{
'status'
:
0
,
'err_msg'
:
'未知'
}
log_server
.
error
(
traceback
.
format_exc
())
self
.
write
(
res
)
def
gen_app
():
return
tornado
.
web
.
Application
(
handlers
=
[(
k
,
v
)
for
k
,
v
in
register_tornado_handlers
.
items
()])
register_tornado_handlers
=
{
'/kw'
:
KwHandler
,
'/excel'
:
DictHandler
}
if
__name__
==
'__main__'
:
port
=
50052
app
=
gen_app
()
print
(
f
'kw监听端口:{port}'
)
app
.
listen
(
port
)
tornado
.
ioloop
.
IOLoop
.
current
()
.
start
()
id_server.py
0 → 100644
View file @
e1f97998
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import
tornado
from
classify_server
import
serve
from
http_server
import
gen_app
from
multiprocessing
import
Process
def
run_http
():
port
=
50052
app
=
gen_app
()
print
(
f
'kw监听端口:{port}'
)
app
.
listen
(
port
)
tornado
.
ioloop
.
IOLoop
.
current
()
.
start
()
def
run_grpc
():
serve
()
def
run
():
p_http
=
Process
(
target
=
run_http
)
p_grpc
=
Process
(
target
=
run_grpc
)
p_http
.
daemon
=
True
p_grpc
.
daemon
=
True
p_http
.
start
()
p_grpc
.
start
()
p_http
.
join
()
p_grpc
.
join
()
if
__name__
==
"__main__"
:
run
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment