armi icon indicating copy to clipboard operation
armi copied to clipboard

Only set the atexit hook when simulation is running

Open drewj-usnctech opened this issue 1 year ago • 2 comments

I often will use CTRL-C in an ipython / python shell to escape out of the current statement. It's all good until I import armi and these hooks will throw a sys.exit https://github.com/terrapower/armi/blob/5b3555cbc6f07470f03d395b00920b2dc4f05290/armi/init.py#L334-L342

I get why these are here: to gracefully cleanup when a simulation is running and an interrupt is thrown. But when I'm just poking around in an ARMI model, or debugging, and I've filled my python shell with setup stuff, a (potentially bad) habit of CTRL-C throws it all away.

Would it be possible to have these atexit calls when something expensive is being performed? Like by the operator?

Other atexit related things

  • https://github.com/terrapower/armi/issues/257
  • https://github.com/terrapower/armi/issues/308

drewj-usnctech avatar Nov 15 '23 05:11 drewj-usnctech

Maaaaaybe.

But ARMI is using the pluggy system, and pluggys whole deal is it loads up all the hooks at import time.

In the past, I've had a really hard time doing anything extra with hooks after the initial pluggy setup.

Off the top of my head, this might be impossible without making a big PR into the pluggy system to allow for post-fact hooks to be registered. BUT, also, maybe I'm wrong. It's worth exploring.

john-science avatar Jan 17 '24 19:01 john-science

@john-science the usage of "hooks" was not meant to be a red herring about pluggy. Rather than these lines being added and called anytime you import armi, could they be guarded in a function that is called when something big is about to happen? Like Operator.operate?

drewj-usnctech avatar Jan 17 '24 21:01 drewj-usnctech