Skip to content

Commit 79bf5ea

Browse files
committed
-
1 parent cacea4e commit 79bf5ea

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

python_toolbox/binary_search/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _binary_search_both(sequence, function, value):
4545
`sequence`.
4646
4747
Note: This function uses `None` to express its inability to find any
48-
matches; therefore, you better not use it on sequences in which None is a
48+
matches; therefore, you better not use it on sequences in which `None` is a
4949
possible item.
5050
'''
5151
# todo: i think this should be changed to return tuples

python_toolbox/cute_profile/cute_profile.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
def profile(statement, globals_, locals_):
21+
'''Profile a statement and return the `Profile`.'''
2122
profile_ = base_profile.Profile()
2223
result = None
2324
try:
@@ -29,13 +30,13 @@ def profile(statement, globals_, locals_):
2930

3031

3132
def profile_expression(expression, globals_, locals_):
33+
'''Profile an expression, and return a tuple of `(result, profile)`.'''
3234
profile_ = profile('result = %s' % expression, globals_, locals_)
3335
return (locals_['result'], profile_)
3436

3537

3638
def profile_ready(condition=None, off_after=True, profile_handler=None):
3739
'''
38-
blocktododoc
3940
Decorator for setting a function to be ready for profiling.
4041
4142
For example:
@@ -50,6 +51,8 @@ def f(x, y):
5051
5152
2. You can set the function to be profiled *when* you want, on the fly.
5253
54+
3. You can have the profile results handled in various useful ways.
55+
5356
How can you set the function to be profiled? There are a few ways:
5457
5558
You can set `f.profiling_on=True` for the function to be profiled on the
@@ -65,7 +68,18 @@ def f(x, y):
6568
turned off afterwards as well. (Unless, again, `f.off_after` is set to
6669
`False`.)
6770
68-
`sort` is an `int` specifying which column the results will be sorted by.
71+
Using `profile_handler` you can say what will be done with profile results.
72+
If `profile_handler` is an `int`, the profile results will be printed, with
73+
the sort order determined by `profile_handler`. If `profile_handler` is a
74+
directory path, profiles will be saved to files in that directory. If
75+
`profile_handler` is details on how to send email, the profile will be sent
76+
as an attached file via email, on a separate thread.
77+
78+
To send email, supply a `profile_handler` like so, with values separated by
79+
newlines:
80+
81+
'ram@rachum.com\nsmtp.gmail.com\nsmtp_username\nsmtppassword'
82+
6983
'''
7084

7185

python_toolbox/cute_profile/profile_handling.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818

1919
class BaseProfileHandler(object):
20+
'''Profile handler which saves the profiling result in some way.'''
2021
__metaclass__ = abc.ABCMeta
2122

2223
def __call__(self, profile):
@@ -34,7 +35,7 @@ def handle(self):
3435

3536

3637
class AuxiliaryThreadProfileHandler(BaseProfileHandler):
37-
38+
'''Profile handler that does its action on a separate thread.'''
3839
thread = None
3940

4041
def handle(self):
@@ -47,6 +48,7 @@ def thread_job(self):
4748

4849

4950
class EmailProfileHandler(AuxiliaryThreadProfileHandler):
51+
'''Profile handler that sends the profile via email on separate thread.'''
5052
def __init__(self, email_address, smtp_server, smtp_user, smtp_password,
5153
use_tls=True):
5254

@@ -76,6 +78,7 @@ def thread_job(self):
7678

7779

7880
class FolderProfileHandler(AuxiliaryThreadProfileHandler):
81+
'''Profile handler that saves the profile to disk on separate thread.'''
7982

8083
def __init__(self, folder_path):
8184
self.folder_path = folder_path
@@ -88,7 +91,7 @@ def thread_job(self):
8891

8992

9093
class PrintProfileHandler(BaseProfileHandler):
91-
94+
'''Profile handler that prints profile data to standard output.'''
9295
def __init__(self, sort_order):
9396
self.sort_order = sort_order
9497

@@ -99,6 +102,7 @@ def handle(self):
99102

100103

101104
def get_profile_handler(profile_handler_string):
105+
'''Parse `profile_handler_string` into a `ProfileHandler` class.'''
102106
if not profile_handler_string or profile_handler_string in \
103107
map(str, range(-1, 5)):
104108
try:

0 commit comments

Comments
 (0)