-
Notifications
You must be signed in to change notification settings - Fork 22
Add hooks to handle simulation failure #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,7 @@ def simulate(config, top_type, env_type=SimEnvironment, reraise=True, | |
top_type.pre_init(env) | ||
env.tracemgr.flush() | ||
with progress_manager(env): | ||
_dump_dict(config_file, config) | ||
top = top_type(parent=None, env=env) | ||
top.elaborate() | ||
env.tracemgr.flush() | ||
|
@@ -183,6 +184,7 @@ def simulate(config, top_type, env_type=SimEnvironment, reraise=True, | |
except BaseException as e: | ||
env.tracemgr.trace_exception() | ||
result['sim.exception'] = repr(e) | ||
top.post_fail() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If either To retain this strategy of calling The new indentation level would be awkward, but it also means that the scope of error catching would exclude A further complication is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing out the possibility of Yes, you are right in the sense that anyone writing a I don't understand what you mean by tear-down any resources that might have been affected by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding resource teardown, the stated goal for this changeset was to allow components to clean-up in the event of an unhandled exception. I'm using "resource" to refer to anything that would be involved in this clean-up; i.e. in the sense of RAII. The key issue I'm pointing out is that if a component has resources to finalize/destroy/close/deallocate, then it will ostensibly be doing that either in The requirement for deallocation of resources to be idempotent is not particularly unusual, but it does impose some cognitive burden on people writing componets with a Regarding the possibility of having a As an aside, I chose to provide hooks for
I wonder if it is sufficient for most models to attach resources that need cleanup to the |
||
raise | ||
else: | ||
result['sim.exception'] = None | ||
|
@@ -192,7 +194,6 @@ def simulate(config, top_type, env_type=SimEnvironment, reraise=True, | |
result['sim.now'] = env.now | ||
result['sim.time'] = env.time() | ||
result['sim.runtime'] = timeit.default_timer() - t0 | ||
_dump_dict(config_file, config) | ||
_dump_dict(result_file, result) | ||
except BaseException as e: | ||
if reraise: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For naming, I would advocate
on_exception()
andexception_hook()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean, replace
post_sim_fail_hook()
withon_exception()
andpost_fail()
withon_exception()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
post_sim_fail_hook()
-->exception_hook()
post_fail()
-->on_exception()
But this is naming is a secondary issue. The big issue is whether this paradigm is actually viable/appropriate.