File: debugger.rst

package info (click to toggle)
circuits 3.1.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,756 kB
  • sloc: python: 15,945; makefile: 130
file content (93 lines) | stat: -rw-r--r-- 2,323 bytes parent folder | download | duplicates (2)
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
Debugger
========


.. module:: circuits.core.debugger


The :mod:`~circuits.core` :class:`~Debugger`
component is the standard way to debug your
circuits applications. It services two purposes:

- Logging events as they flow through the system.
- Logging any exceptions that might occurs in your application.


Usage
-----


Using the :class:`~Debugger` in your application is
very straight forward just like any other component
in the circuits component library. Simply add it
to your application and register it somewhere
(*it doesn't matter where*).


Example:

.. code-block:: python
    :linenos:
    
    from circuits import Component, Debugger
    
    
    class App(Component):
        """Your Application"""
    
    
    app = Appp()
    Debugger().register(app)
    app.run()


Sample Output(s)
----------------


Here are some example outputs that you should
expect to see when using the :class:`~Debugger`
component in your application.

Example Code:

.. code-block:: python
    :linenos:
       
    from circuits import Event, Component, Debugger
    
    
    class foo(Event):
        """foo Event"""
    
    
    class App(Component):
    
        def foo(self, x, y):
            return x + y
    
    
    app = App() + Debugger()
    app.start()

Run with::
    
    python -i app.py

Logged Events::
    
    <registered[*] (<Debugger/* 27098:App (queued=0) [S]>, <App/* 27098:App (queued=2) [R]> )>
    <started[*] (<App/* 27098:App (queued=1) [R]> )>
    >>> app.fire(foo(1, 2))
    <Value () result: False errors: False for <foo[*] (1, 2 )>
    >>> <foo[*] (1, 2 )>

Logged Exceptions::
    
    >>> app.fire(foo())
    <Value () result: False errors: False for <foo[*] ( )>
    >>> <foo[*] ( )>
    <exception[*] (<type 'exceptions.TypeError'>, TypeError('foo() takes exactly 3 arguments (1 given)',), ['  File "/home/prologic/work/circuits/circuits/core/manager.py", line 561, in _dispatcher\n    value = handler(*eargs, **ekwargs)\n'] handler=<bound method App.foo of <App/* 27098:App (queued=1) [R]>>, fevent=<foo[*] ( )>)>
    ERROR <handler[*.foo] (App.foo)> (<foo[*] ( )>) {<type 'exceptions.TypeError'>}: foo() takes exactly 3 arguments (1 given)
      File "/home/prologic/work/circuits/circuits/core/manager.py", line 561, in _dispatcher
          value = handler(*eargs, **ekwargs)