scistag.vislog.visual_log_autoreloader.VisualLogAutoReloader

class VisualLogAutoReloader[source]

Bases: object

Methods

get_cache_backup

Shall return the last VisualLog's cache data from the previous execution session.

get_test_client

Returns the Flask/FastAPI test client if started in test mode :return: The test client

is_main

Returns if the file from which you call this method was originally the __main__ module when the AutoReloader was initialized.

reset

Resets the auto-reloader to it's base settings to provide a clean setup for testing it.

set_log

The current log.

setup

Setups the envelope VisualLog into which the live updating one will get embedded.

start

Starts the auto-reloading service

terminate

Informs the auto-reloader that it shall quit its autoreload loop

update_content

Updates the log's content by rendering first the embedded log and then the main (server) log which embeds it.

Attributes

__annotations__

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

_access_lock

Multithreading access lock

_cache_backup

A backup of the log's cache from the last execution session

_embedded_log

The log which shall get embedded.

_initial_filename

The name of the source file which initially started the reload process

_reloading

Defines if the log is currently reloading

_shall_terminate

Defines if the auto-reloader shall terminate and quit its infinite loop

_test_client

The server test client (if started in testing mode)

content

The last file content state

error_count

The count of often the file count not be reloaded due to errors

imp_module

The name of the module we need to reimport

main_log

The main log which is staying alive during the restart sessions and is connected to the http server to host it's content.

reload_count

The count how often the modules were reloaded since start

testing

Defines if the server shall be started in test_mode

was_sick

Flag if the last time there was an error which stopped the reloading

classmethod _run_loop()[source]

Handles the main loop which verifies if any element was modified and reloads all modified modules if required.

classmethod get_cache_backup()[source]

Shall return the last VisualLog’s cache data from the previous execution session.

Return type

Optional[Cache]

Returns

The cache object if one was “rescued”, otherwise None

classmethod get_test_client()[source]

Returns the Flask/FastAPI test client if started in test mode :return: The test client

classmethod is_main(_stack_level=1)[source]

Returns if the file from which you call this method was originally the __main__ module when the AutoReloader was initialized.

Parameters

_stack_level – Defines if the stack depth at which the call origin shall be verified. By default the calling function (1).

Return type

bool

Returns

True if the function from which this method was called was once the “__main__” module.

classmethod reset()[source]

Resets the auto-reloader to it’s base settings to provide a clean setup for testing it.

classmethod set_log(log)[source]

The current log. As there log will get recreated each turn this object will change when ever the user’s log gets updated.

Parameters

log – The new log of the current run

classmethod setup(refresh_time_s=0.1, **params)[source]

Setups the envelope VisualLog into which the live updating one will get embedded.

Parameters
  • refresh_time_s (float) –

    The (maximum) refresh time in seconds and thus also about the delay between saving the file and seeing the result on screen.

    The browser will not replace/refresh the page if the value is quite low as the update script will detect there were no changes.

  • params – Additional creation parameters. See VisualLog.

classmethod start(log, host_name='127.0.0.1', port=8010, public_ips=None, url_prefix='', check_time_s=None, server_params=None, _stack_level=1)[source]

Starts the auto-reloading service

Parameters
  • log (VisualLog) –

    The (initial) log which shall be provided by the service

    The log which shall be visualized in the live view. Due to the restarting/module reloading approach this log will be re-created each start and thus the object updated.

  • host_name (str | None) –

    The host name at which the log shall be hosted.

    Localhost by default.

    If None is passed no server will be started and no interaction is possible except via the console.

  • port (int | tuple[int, int]) – The port ot listen at or a port range to select the first port within. 8010 by default. 0 for a random port.

  • public_ips (str | list[str] | None) –

    If you run the service on a virtual machine in the cloud you can pass its public IPs to log the correct connection URls to the console.

    If you pass “auto” as ip the public IP will be auto-detected via ipify.

  • url_prefix (str) –

    The url prefix at which the service shall be hosted.

    ”” = At http://server “log/” = At http://server/log

  • server_params (dict | None) – Additional server parameters to be passed into VisualLivelog.run_server() server main loop.

  • check_time_s (float | None) – The time interval at which files are checked for modification.

  • _stack_level – The (relative) stack level of the file which shall be auto_reloaded.

classmethod terminate()[source]

Informs the auto-reloader that it shall quit its autoreload loop

classmethod update_content()[source]

Updates the log’s content by rendering first the embedded log and then the main (server) log which embeds it.

_access_lock = <scistag.common.mt.stag_lock.StagLock object>

Multithreading access lock

_cache_backup: Union['Cache', None] = None

A backup of the log’s cache from the last execution session

_embedded_log: VisualLog | None = None

The log which shall get embedded. (the actual content).

This log will be re-created each modification turn.

_initial_filename: str = ''

The name of the source file which initially started the reload process

_reloading: bool = False

Defines if the log is currently reloading

_shall_terminate = False

Defines if the auto-reloader shall terminate and quit its infinite loop

_test_client = None

The server test client (if started in testing mode)

content = None

The last file content state

error_count = 0

The count of often the file count not be reloaded due to errors

imp_module = None

The name of the module we need to reimport

main_log: VisualLog | None = None

The main log which is staying alive during the restart sessions and is connected to the http server to host it’s content.

reload_count = 0

The count how often the modules were reloaded since start

testing: bool = False

Defines if the server shall be started in test_mode

was_sick: bool = False

Flag if the last time there was an error which stopped the reloading