Skip to content

Commit

Permalink
issue #139: add profiling=True option to mitogen.main().
Browse files Browse the repository at this point in the history
  • Loading branch information
dw committed Mar 19, 2018
1 parent 017e810 commit 8e2b07a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions mitogen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
parent_ids = []


def main(log_level='INFO'):
def main(log_level='INFO', profiling=False):
"""
Convenience decorator primarily useful for writing discardable test
scripts.
Expand All @@ -81,6 +81,13 @@ def main(log_level='INFO'):
Logging package level to configure via
:py:func:`mitogen.utils.log_to_file`.
:param bool profiling:
If :py:data:`True`, equivalent to setting
:py:attr:`mitogen.master.Router.profiling` prior to router
construction. This causes ``/tmp`` files to be created everywhere at
the end of a successful run with :py:mod:`cProfile` output for every
thread.
Example:
::
Expand All @@ -101,7 +108,9 @@ def main(router):
def wrapper(func):
if func.__module__ != '__main__':
return func
from mitogen import utils
import mitogen.master
import mitogen.utils
mitogen.master.Router.profiling = profiling
utils.log_to_file(level=log_level)
return utils.run_with_router(func)
return wrapper

0 comments on commit 8e2b07a

Please sign in to comment.