Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
python-handel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bliss
python-handel
Commits
d040c8d5
Commit
d040c8d5
authored
Oct 23, 2017
by
Vincent Michel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add gevent compatibility
parent
3c491e17
Pipeline
#1252
passed with stages
in 2 minutes and 34 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
2 deletions
+81
-2
README.md
README.md
+11
-0
handel/gevent.py
handel/gevent.py
+47
-0
scripts/handel-server
scripts/handel-server
+2
-1
setup.py
setup.py
+1
-1
tests/test_gevent.py
tests/test_gevent.py
+20
-0
No files found.
README.md
View file @
d040c8d5
...
@@ -22,6 +22,7 @@ Run requirements:
...
@@ -22,6 +22,7 @@ Run requirements:
-
cffi
-
cffi
-
numpy
-
numpy
-
gevent (optional)
Test requirements:
Test requirements:
...
@@ -64,6 +65,16 @@ Example usage:
...
@@ -64,6 +65,16 @@ Example usage:
array
([
13260
,
52275
,
256
,
...,
0
,
0
,
0
],
dtype
=
uint32
)
array
([
13260
,
52275
,
256
,
...,
0
,
0
,
0
],
dtype
=
uint32
)
```
```
Gevent mode
-----------
Make the interface gevent-compatible using:
```
python
>>>
from
handel.gevent
import
patch
>>>
patch
()
```
Tests
Tests
-----
-----
...
...
handel/gevent.py
0 → 100644
View file @
d040c8d5
"""Provide gevent compatibility.
Usage:
>>> from handel.gevent import patch
>>> patch()
"""
from
__future__
import
absolute_import
from
functools
import
wraps
from
gevent
import
threadpool
from
.interface
import
handel
# Green pool
# The 'maxsize=1' argument provides implicit locking
POOL
=
threadpool
.
ThreadPool
(
maxsize
=
1
)
# Green decorator
def
green
(
func
,
pool
=
POOL
):
"""Make a given function gevent-compatible by running
it in a gevent threadpool."""
@
wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
return
pool
.
apply
(
func
,
args
,
kwargs
)
return
wrapper
# Patch function
def
patch
():
"""Provide gevent compatibility.
Usage:
>>> from handel.gevent import patch
>>> patch()
"""
for
name
in
dir
(
handel
):
if
name
.
startswith
(
'xia'
):
func
=
getattr
(
handel
,
name
)
setattr
(
handel
,
name
,
green
(
func
))
scripts/handel-server
View file @
d040c8d5
...
@@ -21,11 +21,12 @@ import sys
...
@@ -21,11 +21,12 @@ import sys
import
zerorpc
import
zerorpc
import
msgpack_numpy
import
msgpack_numpy
import
handel.gevent
import
handel.interface
as
hi
import
handel.interface
as
hi
# Patching
# Patching
handel
.
gevent
.
patch
()
msgpack_numpy
.
patch
()
msgpack_numpy
.
patch
()
...
...
setup.py
View file @
d040c8d5
...
@@ -13,7 +13,7 @@ setup(
...
@@ -13,7 +13,7 @@ setup(
packages
=
[
'handel'
],
packages
=
[
'handel'
],
install_requires
=
[
'cffi'
,
'numpy'
],
install_requires
=
[
'cffi'
,
'numpy'
],
setup_requires
=
[
'pytest-runner'
,
'pytest'
]
if
TESTING
else
[],
setup_requires
=
[
'pytest-runner'
,
'pytest'
]
if
TESTING
else
[],
tests_require
=
[
'pytest-cov'
,
'mock'
],
tests_require
=
[
'pytest-cov'
,
'mock'
,
'gevent'
],
description
=
"Python binding for the Handel library"
,
description
=
"Python binding for the Handel library"
,
long_description
=
long_description
,
long_description
=
long_description
,
...
...
tests/test_gevent.py
0 → 100644
View file @
d040c8d5
import
mock
def
test_gevent_compatibility
():
with
mock
.
patch
(
'cffi.FFI.dlopen'
)
as
dlopen
:
# Declare xiaSomeFunction
handel
=
dlopen
.
return_value
original
=
handel
.
xiaSomeFunction
original
.
__name__
=
'xiaSomeFunction'
original
.
return_value
=
'Some result'
# Patching
from
handel.gevent
import
patch
from
handel
import
interface
assert
patch
()
is
None
# Checking
assert
interface
.
handel
.
xiaSomeFunction
.
__name__
==
'xiaSomeFunction'
assert
interface
.
handel
.
xiaSomeFunction
(
1
,
a
=
2
)
is
'Some result'
original
.
assert_called_once_with
(
1
,
a
=
2
)
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