Skip to main content

A package containing many useful utilities

Project description

Vpack

Python Versions PyPI Versions Publish to PyPI

A package containing a lot of useful utilities for Python developing and debugging.

Features

  • Sigview: press Ctrl+C to print the current stack instead of exiting.
  • Breakpt: set always-on, at-time, on-error breakpoints conveniently.
  • Reload: reload modules by names.

To-do:

  • Vartrace: figure out how a variable changes over time, with a statistical chart or a live counter.

Installation

pip install --upgrade vpack

Examples

Sigview

Sigview is a signal handler. It will print the current running information (e.g. file, lineno, code, stack) when Ctrl+C is pressed.

Sigview Demo

Enable sigview:

from vpack import sigview
sigview.enable()
# your code goes here

Now run your script and you will see the following output:

$ python examples/sigview_example.py
(vpack): Sigview enabled. Press ^C to see the current frame. Press ^C again to exit.
1
2
1

Press Ctrl+C to see the current frame, possible outputs:

^C(vpack): Current file:
examples/sigview_example.py:11 in main
(vpack): Current stask:
+----------------------------------------------------------+
| File "examples/sigview_example.py", line 14, in <module> |
|   main()                                                 |
|                                                          |
| File "examples/sigview_example.py", line 11, in main     |
|   time.sleep(2)                                          |
+----------------------------------------------------------+

Press Ctrl+C twice (in 0.5 seconds) to exit.

You can also use sigview.enable(openshell=True) to open a new shell when Ctrl+C is pressed.

See sigview_example.py and sigview_openshell_example.py.md for more details.

Breakpt

Breakpt is a convenient way to set breakpoints.

.at(n) will try to open an interactive IPython shell (or pdb) when this line has been executed n times. .onerror() will try to open a PDB shell when an Exception is raised.

You can use breakpt.enable() and breakpt.disable() to enable and disable breakpt.

from vpack import breakpt

for i in range(10):
    print(i)
    breakpt.at(8) # break at i = 7
    breakpt.at(5) # break at i = 4

for i in range(6):
    print(i)
    if i == 2: breakpt.disable() # disable breakpt
    if i == 4: breakpt.enable() # enable breakpt
    breakpt.always() # break at i = 0, 1, 4, 5

breakpt.onerror()
a = [1, 2, 3]
for i in range(5):
    print(a[i]) # will break at i = 3

See breakpt_example.py for more details.

Reload

Reload modules by names, see reload_example.py for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vpack-0.0.11.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

vpack-0.0.11-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page