Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
corepost
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
nexlab
corepost
Commits
bded1c1b
Commit
bded1c1b
authored
Aug 25, 2011
by
Jacek Furmankiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
@defer.inlineCallbacks support
parent
a7e87051
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
6 deletions
+29
-6
README.md
README.md
+13
-2
server.py
src/corepost/server.py
+11
-3
server_test.py
src/corepost/test/server_test.py
+5
-1
No files found.
README.md
View file @
bded1c1b
...
@@ -30,11 +30,22 @@ Example:
...
@@ -30,11 +30,22 @@ Example:
if __name__ == '__main__':
if __name__ == '__main__':
app.run()
app.run()
@defer.inlineCallbacks support
------------------------------
If you want a deferred async method, just complete the request yourself, instead of returning a string response
@app.route("/",Http.GET)
@defer.inlineCallbacks
def root(request):
val = yield db.query("SELECT ....")
request.write(val)
request.finish()
Performance
Performance
-----------
-----------
Pushing 8,000+ TPS on a simple 'Hello World' app using 'ab -n 100000 -c 200'
On par with raw
*twisted.web*
performance. Minimal overhead for URL routing and function argument extraction.
for benchmarking while running on PyPy 1.6
Plans
Plans
-----
-----
...
...
src/corepost/server.py
View file @
bded1c1b
...
@@ -4,9 +4,9 @@ Main server classes
...
@@ -4,9 +4,9 @@ Main server classes
@author: jacekf
@author: jacekf
'''
'''
import
re
,
copy
import
re
,
copy
from
twisted.internet
import
reactor
from
twisted.internet
import
reactor
,
defer
from
twisted.web.resource
import
Resource
from
twisted.web.resource
import
Resource
from
twisted.web.server
import
Site
from
twisted.web.server
import
Site
,
NOT_DONE_YET
from
collections
import
defaultdict
from
collections
import
defaultdict
from
enums
import
MediaType
from
enums
import
MediaType
from
corepost.enums
import
Http
from
corepost.enums
import
Http
...
@@ -165,7 +165,15 @@ class CorePost(Resource):
...
@@ -165,7 +165,15 @@ class CorePost(Resource):
# if POST/PUT, check if we need to automatically parse JSON
# if POST/PUT, check if we need to automatically parse JSON
# TODO
# TODO
return
urlrouter
.
call
(
request
,
**
allargs
)
#handle Deferreds natively
val
=
urlrouter
.
call
(
request
,
**
allargs
)
if
isinstance
(
val
,
defer
.
Deferred
):
# we assume the method will call request.finish()
return
NOT_DONE_YET
else
:
return
val
else
:
else
:
return
self
.
__renderError
(
request
,
404
,
"URL '
%
s' not found
\n
"
%
request
.
path
)
return
self
.
__renderError
(
request
,
404
,
"URL '
%
s' not found
\n
"
%
request
.
path
)
...
...
src/corepost/test/server_test.py
View file @
bded1c1b
...
@@ -5,12 +5,16 @@ Server tests
...
@@ -5,12 +5,16 @@ Server tests
from
corepost.server
import
CorePost
from
corepost.server
import
CorePost
from
corepost.enums
import
Http
from
corepost.enums
import
Http
from
twisted.internet
import
defer
app
=
CorePost
()
app
=
CorePost
()
@
app
.
route
(
"/"
,
Http
.
GET
)
@
app
.
route
(
"/"
,
Http
.
GET
)
@
defer
.
inlineCallbacks
def
root
(
request
,
**
kwargs
):
def
root
(
request
,
**
kwargs
):
return
"
%
s"
%
kwargs
yield
1
request
.
write
(
"
%
s"
%
kwargs
)
request
.
finish
()
@
app
.
route
(
"/test"
,
Http
.
GET
)
@
app
.
route
(
"/test"
,
Http
.
GET
)
def
test
(
request
,
**
kwargs
):
def
test
(
request
,
**
kwargs
):
...
...
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