Skip to main content

Restart debugging your program in the function that failed.

Project description

Restart debugging your program in the function that failed.

Minimal hot-reload-and-restart library.

Usage:

Wrap any function you expect to crash in @hot_restart.wrap:

import hot_restart

@hot_restart.wrap
def my_func():
    ...

@hot_restart.wrap_class
class MyClass:

    def forward(self, x):
        super().forward(x * 2)

Alternatively, call hot_restart.wrap_module() after your functions and classes are defined.

When a wrapped function crashes, hot_restart will open a post mortem debugger in the wrapped function, with the rest of the stack still live above that function call.

Then you can modify the source code of your crashing function, and (c)ontinue from the debugger, and hot_restart will reload the source of that function (and only that function).

Edge Cases

You can also trigger a full module reload with hot_restart.reload_module(), although that may result in duplicate (i.e. conflicting) class defintions.

hot_restart uses source re-writing to handle the common cases, and does not patch the byte-code of functions.

super() Calls

hot_restart rewrites super() into super(type(self, self) in reloaded source (original source is loaded intact). This prevents methods from acquiring a closure variable __class__, which would break in many cases, but this re-write can fail if self is not defined where super() is used. This restriction may be removed in the future.

To work around this, you can use the two-argument form of super() manually.

Closures and Nested Functions

hot_restart will patch in old closure variables into newly defined functions, as long as hot_restart.wrap is the innermost decorator. However, functions cannot add new closure variables without a full module reload. Functions can still gain new arguments.

For nested functions, hot_restart.wrap_module() cannot find the inner function, so hot_restart.wrap() must be used manually.

If hot_restart.wrap is not the inner most decorator, then closure variables will be lost.

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

hot_restart-0.1.1.tar.gz (11.4 kB view hashes)

Uploaded Source

Built Distribution

hot_restart-0.1.1-py2.py3-none-any.whl (10.0 kB view hashes)

Uploaded Python 2 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