AtomicOutput
This module creates the output file only if no errors occurred.
AtomicOutput()
Bases: MessageHandlerFile
Create output file only if no errors occurred.
abort(message)
Abort the operation with an error message and discard the output.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The error message.
TYPE:
|
close()
Close the output file.
discard()
Discard the output file.
get_file()
Get the output file handle, opening the file if necessary.
| RETURNS | DESCRIPTION |
|---|---|
IO[Any]
|
The output file handle. |
get_filename()
Get the output filename.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The output filename. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the output filename is not set. |
run(code)
Run code that produces the output file. If an uncaught exception occurs, the output file is discarded.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
The function to call to produce the output file.
TYPE:
|
set_filename(filename, binary=False)
Set output filename.
| PARAMETER | DESCRIPTION |
|---|---|
filename
|
The output filename.
TYPE:
|
binary
|
Whether to open the file in binary mode.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the output file is already open. |
set_only_if_changed(value)
Set whether not to overwrite an existing file if it remains unchanged. This avoids unnecessary rebuilds.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the output file is already open. |