Read Watches in Python
C Objective-C Python Other
Switch branches/tags
Nothing to show
Clone or download
Latest commit 18e13ff Sep 29, 2015
Permalink
Failed to load latest commit information.
demos mutable mapping example Sep 29, 2015
src better disabling of watch targets to avoid recursion errors Sep 29, 2015
MANIFEST.in first commit Sep 28, 2015
README.md first commit Sep 28, 2015
setup.py first commit Sep 28, 2015

README.md

Disclaimer

dutc = Don't Use This Code (!!)

Compatibility

  • Python 3.5 or higher
  • Linux or OS X
  • need build toolchain (prob. need gcc)

Read Watches in Python

>>> import rwatch # enable functionality
>>> from sys import setrwatch, getrwatch
>>> x, y, z = object(), object(), object()
>>> def view(frame, obj):
...     print(frame, obj)
...     return obj
...
>>> setrwatch({id(x): view, id(y): view})
>>> getrwatch()
{139825758638208: <function view at 0x7f2bb89a59d8>, 139825758638224: <function view at 0x7f2bb89a59d8>}
>>> x
<frame object at 0x7f2bb8ad9ba8> <object object at 0x7f2bb8ac9080>
<object object at 0x7f2bb8ac9080>
>>> y
<frame object at 0x7f2bb8ad9d48> <object object at 0x7f2bb8ac9090>
<object object at 0x7f2bb8ac9090>
>>> z
<object object at 0x7f2bb8ac90a0>

Lessons:

  • read watches are a very useful tool for debugging
  • it's actually very useful for a language to have a runtime
  • there are some hidden equivalencies between, e.g., read watches and perfect proxy objects