Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
2a365aa9
Commit
2a365aa9
authored
Sep 21, 2017
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace `with_context` parameter with mitogen.core.takes_econtext decorator
parent
8d4005c2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
18 deletions
+10
-18
mitogen/core.py
mitogen/core.py
+1
-3
mitogen/master.py
mitogen/master.py
+9
-15
No files found.
mitogen/core.py
View file @
2a365aa9
...
@@ -1138,9 +1138,7 @@ class ExternalContext(object):
...
@@ -1138,9 +1138,7 @@ class ExternalContext(object):
def
_dispatch_calls
(
self
):
def
_dispatch_calls
(
self
):
for
msg
,
data
in
self
.
channel
:
for
msg
,
data
in
self
.
channel
:
LOG
.
debug
(
'_dispatch_calls(%r)'
,
data
)
LOG
.
debug
(
'_dispatch_calls(%r)'
,
data
)
with_context
,
modname
,
klass
,
func
,
args
,
kwargs
=
data
modname
,
klass
,
func
,
args
,
kwargs
=
data
if
with_context
:
args
=
(
self
,)
+
args
try
:
try
:
obj
=
__import__
(
modname
,
{},
{},
[
''
])
obj
=
__import__
(
modname
,
{},
{},
[
''
])
...
...
mitogen/master.py
View file @
2a365aa9
...
@@ -659,9 +659,9 @@ class Context(mitogen.core.Context):
...
@@ -659,9 +659,9 @@ class Context(mitogen.core.Context):
else
:
else
:
LOG
.
debug
(
'_discard_result: %r'
,
data
)
LOG
.
debug
(
'_discard_result: %r'
,
data
)
def
call_async
(
self
,
with_context
,
fn
,
*
args
,
**
kwargs
):
def
call_async
(
self
,
fn
,
*
args
,
**
kwargs
):
LOG
.
debug
(
'%r.call_async(%r,
%r,
*%r, **%r)'
,
LOG
.
debug
(
'%r.call_async(%r, *%r, **%r)'
,
self
,
with_context
,
fn
,
args
,
kwargs
)
self
,
fn
,
args
,
kwargs
)
if
isinstance
(
fn
,
types
.
MethodType
)
and
\
if
isinstance
(
fn
,
types
.
MethodType
)
and
\
isinstance
(
fn
.
im_self
,
(
type
,
types
.
ClassType
)):
isinstance
(
fn
.
im_self
,
(
type
,
types
.
ClassType
)):
...
@@ -669,27 +669,22 @@ class Context(mitogen.core.Context):
...
@@ -669,27 +669,22 @@ class Context(mitogen.core.Context):
else
:
else
:
klass
=
None
klass
=
None
call
=
(
with_context
,
fn
.
__module__
,
klass
,
fn
.
__name__
,
args
,
kwargs
)
self
.
send
(
self
.
send
(
mitogen
.
core
.
Message
.
pickled
(
mitogen
.
core
.
Message
.
pickled
(
call
,
(
fn
.
__module__
,
klass
,
fn
.
__name__
,
args
,
kwargs
)
,
handle
=
mitogen
.
core
.
CALL_FUNCTION
,
handle
=
mitogen
.
core
.
CALL_FUNCTION
,
reply_to
=
self
.
router
.
add_handler
(
self
.
_discard_result
),
reply_to
=
self
.
router
.
add_handler
(
self
.
_discard_result
),
)
)
)
)
def
call_with_deadline
(
self
,
deadline
,
with_context
,
fn
,
*
args
,
**
kwargs
):
def
call_with_deadline
(
self
,
deadline
,
fn
,
*
args
,
**
kwargs
):
"""Invoke `fn([context,] *args, **kwargs)` in the external context.
"""Invoke `fn([context,] *args, **kwargs)` in the external context.
If `with_context` is ``True``, pass its
:py:class:`ExternalContext <mitogen.core.ExternalContext>` instance as
the first parameter.
If `deadline` is not ``None``, expire the call after `deadline`
If `deadline` is not ``None``, expire the call after `deadline`
seconds. If `deadline` is ``None``, the invocation may block
seconds. If `deadline` is ``None``, the invocation may block
indefinitely."""
indefinitely."""
LOG
.
debug
(
'%r.call_with_deadline(%r, %r,
%r,
*%r, **%r)'
,
LOG
.
debug
(
'%r.call_with_deadline(%r, %r, *%r, **%r)'
,
self
,
deadline
,
with_context
,
fn
,
args
,
kwargs
)
self
,
deadline
,
fn
,
args
,
kwargs
)
if
isinstance
(
fn
,
types
.
MethodType
)
and
\
if
isinstance
(
fn
,
types
.
MethodType
)
and
\
isinstance
(
fn
.
im_self
,
(
type
,
types
.
ClassType
)):
isinstance
(
fn
.
im_self
,
(
type
,
types
.
ClassType
)):
...
@@ -697,10 +692,9 @@ class Context(mitogen.core.Context):
...
@@ -697,10 +692,9 @@ class Context(mitogen.core.Context):
else
:
else
:
klass
=
None
klass
=
None
call
=
(
with_context
,
fn
.
__module__
,
klass
,
fn
.
__name__
,
args
,
kwargs
)
response
=
self
.
send_await
(
response
=
self
.
send_await
(
mitogen
.
core
.
Message
.
pickled
(
mitogen
.
core
.
Message
.
pickled
(
call
,
(
fn
.
__module__
,
klass
,
fn
.
__name__
,
args
,
kwargs
)
,
handle
=
mitogen
.
core
.
CALL_FUNCTION
handle
=
mitogen
.
core
.
CALL_FUNCTION
),
),
deadline
deadline
...
@@ -713,7 +707,7 @@ class Context(mitogen.core.Context):
...
@@ -713,7 +707,7 @@ class Context(mitogen.core.Context):
def
call
(
self
,
fn
,
*
args
,
**
kwargs
):
def
call
(
self
,
fn
,
*
args
,
**
kwargs
):
"""Invoke `fn(*args, **kwargs)` in the external context."""
"""Invoke `fn(*args, **kwargs)` in the external context."""
return
self
.
call_with_deadline
(
None
,
False
,
fn
,
*
args
,
**
kwargs
)
return
self
.
call_with_deadline
(
None
,
fn
,
*
args
,
**
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