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
6a10ab60
Commit
6a10ab60
authored
Oct 05, 2017
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs: move mitogen.utils docs to Sphinx.
parent
270b242e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
23 deletions
+52
-23
docs/api.rst
docs/api.rst
+52
-2
mitogen/utils.py
mitogen/utils.py
+0
-21
No files found.
docs/api.rst
View file @
6a10ab60
...
...
@@ -675,8 +675,58 @@ Broker Class
Utility Functions
=================
.. automodule:: mitogen.utils
:members:
.. module:: mitogen.utils
A random assortment of utility functions useful on masters and children.
.. currentmodule:: mitogen.utils
.. function:: disable_site_packages
Remove all entries mentioning ``site-packages`` or ``Extras`` from the
system path. Used primarily for testing on OS X within a virtualenv, where
OS X bundles some ancient version of the :py:mod:`six` module.
.. currentmodule:: mitogen.utils
.. function:: log_to_file (path=None, io=True, level='INFO')
Install a new :py:class:`logging.Handler` writing applications logs to the
filesystem. Useful when debugging slave IO problems.
:param str path:
If not ``None``, a filesystem path to write logs to. Otherwise, logs
are written to :py:data:`sys.stderr`.
:param bool io:
If ``True``, include extremely verbose IO logs in the output. Useful
for debugging hangs, less useful for debugging application code.
:param str level:
Name of the :py:mod:`logging` package constant that is the minimum
level to log at. Useful levels are ``DEBUG``, ``INFO``, ``WARNING``,
and ``ERROR``.
.. currentmodule:: mitogen.utils
.. function:: run_with_router(func, \*args, \**kwargs)
Arrange for `func(router, \*args, \**kwargs)` to run with a temporary
:py:class:`mitogen.master.Router`, ensuring the Router and Broker are
correctly shut down during normal or exceptional return.
:returns:
`func`'s return value.
.. currentmodule:: mitogen.utils
.. decorator:: with_router
Decorator version of :py:func:`run_with_router`. Example:
.. code-block:: python
@with_router
def do_stuff(router, arg):
pass
do_stuff(blah, 123)
Exceptions
...
...
mitogen/utils.py
View file @
6a10ab60
"""
A random assortment of utility functions useful on masters and slaves.
"""
import
logging
import
sys
...
...
@@ -14,17 +11,12 @@ LOG = logging.getLogger('mitogen')
def
disable_site_packages
():
"""Remove all entries mentioning site-packages or Extras from the system
path. Used primarily for testing on OS X within a virtualenv, where OS X
bundles some ancient version of the 'six' module."""
for
entry
in
sys
.
path
[:]:
if
'site-packages'
in
entry
or
'Extras'
in
entry
:
sys
.
path
.
remove
(
entry
)
def
log_to_file
(
path
=
None
,
io
=
True
,
level
=
'INFO'
):
"""Install a new :py:class:`logging.Handler` writing applications logs to
the filesystem. Useful when debugging slave IO problems."""
log
=
logging
.
getLogger
(
''
)
if
path
:
fp
=
open
(
path
,
'w'
,
1
)
...
...
@@ -45,9 +37,6 @@ def log_to_file(path=None, io=True, level='INFO'):
def
run_with_router
(
func
,
*
args
,
**
kwargs
):
"""Arrange for `func(router, *args, **kwargs)` to run with a temporary
:py:class:`mitogen.master.Router`, ensuring the Router and Broker are
correctly shut down during normal or exceptional return."""
broker
=
mitogen
.
master
.
Broker
()
router
=
mitogen
.
master
.
Router
(
broker
)
try
:
...
...
@@ -58,16 +47,6 @@ def run_with_router(func, *args, **kwargs):
def
with_router
(
func
):
"""Decorator version of :py:func:`run_with_router`. Example:
.. code-block:: python
@with_router
def do_stuff(router, arg):
pass
do_stuff(blah, 123)
"""
def
wrapper
(
*
args
,
**
kwargs
):
return
run_with_router
(
func
,
*
args
,
**
kwargs
)
wrapper
.
func_name
=
func
.
func_name
...
...
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