luminal.managers.handler
Module Contents
Classes
Wraps an |
- class Handler(logging, name, filepath, checksum, instance)
Wraps an
IPhotonor another inherited photon base class and provides access to local instance information.- Parameters:
- property checksum: str
Returns the checksum of the original photon file.
- Returns:
The checksum of the original file containing the photon.
- Return type:
- async static _get_checksum(filename, block=2**20)
|coro|Generates a calculated
SHA512hash for a given file.- Parameters:
- Returns:
The calculated
SHA512hash of the file, orNoneif there was an error generating the checksum.- Return type:
Optional[
str]
Notes
This function generates a
SHA512hash for a given file by reading the file in blocks and hashing each block. The generated hash is a digest checksum (a unique fixed-sized representation of the file content). The file is treated as a binary file (read in ‘rb’ mode) for proper handling of all types of files.The reason
SHA512was chosen is purely for the lack of collisions at runtime when performing dynamic checks.If the specified file cannot be found or if there are any errors while generating the checksum, returns
None.
- async _clear_module_references()
|coro|Clears all references for the current handler module and its submodules in sys.modules.
- Returns:
A flag value indicating whether references were cleared successfully.
- Return type:
Notes
This function clears all references to the current module and any of its submodules in
sys.modules. It is used to ensure that a module can be safely deleted from memory without any leftover references. The function returnsTrueif the operation to clear references succeeds. Default isFalse.
- async _stop_photon_threads()
|coro|This function stops all of the running threads that belong to the current photon’s thread group. It is typically called during a photon unload to ensure that no threads are left running that could cause errors or conflicts with a new, reloaded photon.
- Returns:
A flag indicating whether all photon threads were successfully stopped. This returns
Trueif all photon threads are successfully stopped. Default isFalse.- Return type:
- async _stop_photon_processes()
|coro|This function is responsible for stopping and terminating all of the child processes spawned by the handler.
- Returns:
A flag indicating whether any child process for the handler were stopped. Default is
False.- Return type:
- async _force_stop()
|coro|This function is responsible for forcefully stopping and halting all the running threads and processes of the handler. It calls the
_stop_photon_threads()and_stop_photon_processes()methods to perform these tasks.- Return type:
None
- async _stop(force_stop=False)
|coro|This function stops the running
IPhotoninstance, halting all the child threads and processes of the instance if any exist. Ifforce_stopisTrue, this function calls the_force_stop()method to stop the instance. Otherwise, it first calls thefinalize()method if present in the current instance. If thefinalize()method does not exist or raises an error, then the_force_stop()method is called.- Parameters:
force_stop (Optional[
bool]) – A boolean flag indicating whether to forcefully stop the photon instance. Default isFalse.- Raises:
PhotonNotInitializedError – If the photon has not been initialized.
- Return type:
None
- async start()
|coro|This function starts running the
IPhotoninstance by creating it if it does not exist already.Notes
If already started, it checks if it’s a
tuple. If the instance is not atuple, it initializes theIPhotoninstance and stores it as a tuple with a second value set toTrue.
- Return type:
None