My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
Mischelaneous or common.
"""
__all__ = ['debug', 'priority', 'fmt_list']

import sys


def debug(trace=True, backtrace=1, other=None, output=sys.stderr):
"""A decorator for debugging purposes. Shows the call arguments, result
and instructions as they are runned."""
from pprint import pprint
import traceback
def debugdeco(func):
def tracer(frame, event, arg):
print>>output, '--- Tracer: %s, %r' % (event, arg)
traceback.print_stack(frame, 1, output)
return tracer
def wrapped(*a, **k):
print>>output
print>>output, '--- Calling %s.%s with:' % (
getattr(func, '__module__', ''),
func.__name__
)
for i in enumerate(a):
print>>output, ' | %s: %s' % i
print>>output, ' | ',
pprint(k, output)
print>>output, ' From:'
for i in traceback.format_stack(sys._getframe(1), backtrace):
print>>output, i,
if other:
print>>output, '--- [ %r ]' % (other(func,a,k))
if trace: sys.settrace(tracer)
ret = func(*a, **k)
if trace: sys.settrace(None)
#~ a = list(a)
print>>output, '--- %s.%s returned: %r' % (
getattr(func, '__module__', ''),
func.__name__,
#~ ret not in a and ret or "ARG%s"%a.index(ret)
ret
)
return ret
return wrapped
return debugdeco


class priority(object):
"""
How these priority flags are interpreted depends largely on the operation
(since that's where these are checked).

======== ===================================================================
Property Description
======== ===================================================================
DEFAULT Use the default_priority set in the Scheduler
-------- -------------------------------------------------------------------
LAST,
NOPRIO Allways scheduler the operation/coroutine at the end of the queue
-------- -------------------------------------------------------------------
CORO Favor the coroutine - if it's the case.
-------- -------------------------------------------------------------------
OP Favor the operation - if it's the case.
-------- -------------------------------------------------------------------
FIRST,
PRIO Allways schedule with priority
======== ===================================================================

"""
DEFAULT = -1
LAST = NOPRIO = 0
CORO = 1
OP = 2
FIRST = PRIO = 3

def fmt_list(lst, lim=100):
if sum(len(i) for i in lst) > lim:
ret = []
length = 0
for i in lst:
if length+len(i)>lim:
ret.append(i[:lim-length] + ' ...')
break
else:
ret.append(i)
length += len(i)
post = ''
if len(ret) < len(lst):
post = " .. %s more" % (len(lst)-len(ret))
return "[%s%s]"%(', '.join(repr(i) for i in ret), post)
else:
return repr(lst)
Show details Hide details

Change log

r588 by ionel.mc on Apr 26, 2009   Diff
Removed trailing spaces. Fixed
inconsistent end of line format.

Merged from amcnabb8's branch.
Go to: 
Project members, sign in to write a code review

Older revisions

r556 by ionel.mc on Jan 03, 2009   Diff
some cleanup like remove useless
imports and a couple of relics of old
past
r515 by ionel.mc on Nov 26, 2008   Diff
added an output stream option to the
debug tracer func
r409 by ionel.mc on Jun 14, 2008   Diff
changed timeouts to be more compact in
terms of number of instances (saves
some memory)
All revisions of this file

File info

Size: 3338 bytes, 93 lines
Hosted by Google Code