Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-04-23 12:17:22 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
580cbb84a9d897c305612c883b56ad697f271d92
580cbb84
1 parent
435e02db
add threading.Lock for cherrypy, or performance suffer.
显示空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
33 行增加
和
2 行删除
trunk/research/api-server/server.py
trunk/research/api-server/server.py
查看文件 @
580cbb8
...
...
@@ -368,7 +368,8 @@ class RESTServers(object):
self
.
__nodes
=
[]
self
.
__last_update
=
datetime
.
datetime
.
now
();
server_ip
=
"192.168.1.142"
;
self
.
__lock
=
threading
.
Lock
()
def
__get_node
(
self
,
device_id
):
for
node
in
self
.
__nodes
:
...
...
@@ -416,6 +417,9 @@ class RESTServers(object):
def
POST
(
self
):
enable_crossdomain
()
try
:
self
.
__lock
.
acquire
()
req
=
cherrypy
.
request
.
body
.
read
()
trace
(
"post to nodes, req=
%
s"
%
(
req
))
try
:
...
...
@@ -437,6 +441,8 @@ class RESTServers(object):
node
.
heartbeat
=
time
.
time
()
return
json
.
dumps
({
"code"
:
Error
.
success
,
"data"
:
{
"id"
:
node
.
id
}})
finally
:
self
.
__lock
.
release
()
'''
id canbe:
...
...
@@ -455,6 +461,9 @@ class RESTServers(object):
def
GET
(
self
,
id
=
None
,
action
=
"play"
,
stream
=
"live/livestream"
,
index
=
None
,
local
=
"false"
,
device_id
=
None
):
enable_crossdomain
()
try
:
self
.
__lock
.
acquire
()
self
.
__refresh_nodes
()
data
=
self
.
__json_dump_nodes
(
self
.
__nodes
)
...
...
@@ -507,6 +516,8 @@ class RESTServers(object):
return
json
.
dumps
(
data
)
#return "id=%s, action=%s, stream=%s, url=%s, index=%s, local=%s"%(id, action, stream, url, index, local)
raise
cherrypy
.
HTTPRedirect
(
url
)
finally
:
self
.
__lock
.
release
()
def
DELETE
(
self
,
id
):
enable_crossdomain
()
...
...
@@ -577,6 +588,10 @@ class RESTNodes(object):
def
__init__
(
self
):
self
.
__nodes
=
[]
# @remark, if there is shared data, such as the self.__nodes,
# we must use lock for cherrypy, or the cpu of cherrypy will high
# and performance suffer.
self
.
__lock
=
threading
.
Lock
()
def
__get_node
(
self
,
id
):
for
node
in
self
.
__nodes
:
...
...
@@ -629,6 +644,9 @@ class RESTNodes(object):
def
GET
(
self
,
type
=
None
,
format
=
None
,
origin
=
None
,
vhost
=
None
,
port
=
None
,
stream
=
None
,
node_id
=
None
):
enable_crossdomain
()
try
:
self
.
__lock
.
acquire
()
self
.
__refresh_nodes
()
data
=
self
.
__json_dump_nodes
(
self
.
__nodes
)
...
...
@@ -671,10 +689,15 @@ class RESTNodes(object):
}})
return
json
.
dumps
({
"code"
:
Error
.
success
,
"data"
:
data
})
finally
:
self
.
__lock
.
release
()
def
PUT
(
self
):
enable_crossdomain
()
try
:
self
.
__lock
.
acquire
()
req
=
cherrypy
.
request
.
body
.
read
()
trace
(
"put to nodes, req=
%
s"
%
(
req
))
try
:
...
...
@@ -708,10 +731,15 @@ class RESTNodes(object):
res
=
json
.
dumps
({
"code"
:
Error
.
success
,
"data"
:
{
"id"
:
node
.
id
,
"peers"
:
peers_data
}})
trace
(
res
)
return
res
finally
:
self
.
__lock
.
release
()
def
POST
(
self
):
enable_crossdomain
()
try
:
self
.
__lock
.
acquire
()
req
=
cherrypy
.
request
.
body
.
read
()
trace
(
"post to nodes, req=
%
s"
%
(
req
))
try
:
...
...
@@ -736,6 +764,8 @@ class RESTNodes(object):
res
=
json
.
dumps
({
"code"
:
Error
.
success
,
"data"
:
{
"id"
:
node
.
id
,
"peers"
:
peers_data
}})
trace
(
res
)
return
res
finally
:
self
.
__lock
.
release
()
def
OPTIONS
(
self
,
*
args
,
**
kwargs
):
enable_crossdomain
()
...
...
@@ -966,7 +996,8 @@ conf = {
'server.socket_port'
:
port
,
'tools.encode.on'
:
True
,
'tools.staticdir.on'
:
True
,
'tools.encode.encoding'
:
"utf-8"
'tools.encode.encoding'
:
"utf-8"
,
'server.thread_pool'
:
2
,
# single thread server.
},
'/'
:
{
'tools.staticdir.dir'
:
static_dir
,
...
...
请
注册
或
登录
后发表评论