lazarus 0.6.3 documentation

lazarus package

«  lazarus   ::   Contents   ::   Contributing  »

lazarus package

Module contents

Functions to restart a process when source changes.

Progress doesn’t come from early risers - progress is made by lazy men looking for easier ways to do things.

lazarus.custom(srcpaths, event_cb=None, poll_interval=1, recurse=True, restart_cb=None, restart_func=None, close_fds=True)[source]

Sets up lazarus in custom mode.

See the default() function for a simpler mode of use.

The custom mode of lazarus is to watch all modules rooted at any of the source paths provided for changes and restart when they take place.

Keyword arguments:

event_cb – Callback invoked when a file rooted at a source path changes. Without specifying an event callback, changes to any module rooted at a source path will trigger a restart.

poll_interval – Rate at which changes will be detected. The default value of 1 means it may take up to one second to detect changes. Decreasing this value may lead to unnecessary overhead.

recurse – Whether to watch all subdirectories of every source path for changes or only the paths provided.

restart_cb – Callback invoked prior to restarting the process; allows for any cleanup to occur prior to restarting. Returning anything other than None in the callback will cancel the restart.

restart_func – Function invoked to restart the process. This supplants the default behavior of using sys.executable and sys.argv.

close_fds – Whether all file descriptors other than stdin, stdout, and stderr should be closed

An example of using a cleanup function prior to restarting:

>>> def cleanup():
...     pass
>>> import lazarus
>>> lazarus.custom(os.curdir, restart_cb=cleanup)
>>> lazarus.stop()

An example of avoiding restarts when any __main__.py changes:

>>> def skip_main(event):
...     if event.src_path == '__main__.py':
...         return False
...     return True
>>> import lazarus
>>> lazarus.custom(os.curdir, event_cb=skip_main)
>>> lazarus.stop()
lazarus.default(restart_cb=None, restart_func=None, close_fds=True)[source]

Sets up lazarus in default mode.

See the custom() function for a more powerful mode of use.

The default mode of lazarus is to watch all modules rooted at PYTHONPATH for changes and restart when they take place.

Keyword arguments:

restart_cb – Callback invoked prior to restarting the process; allows for any cleanup to occur prior to restarting. Returning anything other than None in the callback will cancel the restart.

restart_func – Function invoked to restart the process. This supplants the default behavior of using sys.executable and sys.argv.

close_fds – Whether all file descriptors other than stdin, stdout, and stderr should be closed

A simple example:

>>> import lazarus
>>> lazarus.default()
>>> lazarus.stop()
lazarus.is_restart_event(event)[source]

Default logic for whether a filesystem event is a restart event.

For example:

>>> import collections
>>> Event = collections.namedtuple('Event', 'src_path dest_path')
>>> vim_ev = Event('foo.py', None)
>>> is_restart_event(vim_ev)
True
>>> sublime_ev = Event('.subl6f0.tmp', '__main__.py')
>>> is_restart_event(sublime_ev)
True

If the event’s source or destination path ends in .py, the event is considered a restart event. This covers most cases where a restart should take place like developers using editors, IDEs, or version control operations.

lazarus.stop()[source]

Stops lazarus, regardless of which mode it was started in.

For example:

>>> import lazarus
>>> lazarus.default()
>>> lazarus.stop()

«  lazarus   ::   Contents   ::   Contributing  »