Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

[Core] Handle script interruptions in the middle of action #238

Closed
mutterroland opened this issue Mar 1, 2019 · 5 comments
Closed

[Core] Handle script interruptions in the middle of action #238

mutterroland opened this issue Mar 1, 2019 · 5 comments
Assignees
Labels
bug Something isn't working core Issue that affect our core functionality

Comments

@mutterroland
Copy link
Contributor

Picture this: You are running the script , it writes data into a json and you stop by from keyboard for whatever reason. Data inside the json will not have the correct format next time the script loads the data into a variable. Basically the script with throw and exception and stop. We have to find a way to prevent that from happening. Not allowing the user to interrupt the process seems off the table because the script can suddenly be stopped for various of reasons.

@mutterroland mutterroland changed the title Handle script interruptions in the middle of action [Core] Handle script interruptions in the middle of action Mar 1, 2019
@danlabici danlabici self-assigned this Mar 1, 2019
@danlabici danlabici added bug Something isn't working core Issue that affect our core functionality labels Mar 1, 2019
@danlabici danlabici added this to the [Prio1] Prepare for Grafana milestone Mar 1, 2019
@danlabici
Copy link
Collaborator

danlabici commented Mar 3, 2019

Current implementation idea:

  • Add a new bool called busy, default will be False
  • Every important function, such as the ones that write to files, before they do anything, they switch busy=True
  • When the function finishes it's work it will switch busy=False
  • If KeyboardInterrupt is detected, first check if we are busy or not. If we are busy, do nothing else exit the script.

Issue

It seems that if we try to catch KeyboardInterrupt the script will still exit, even if we type pass as detailed below:

try:
    run_some_important_logic()
except KeyboardInterrupt:
    print("You can't close the app right now!")
    pass

@lundjordan / @escapewindow Any tips and tricks here?

@escapewindow
Copy link

16:04 <aki-away> write to a tmpfile, copy it to the real location when you're done. i'm assuming the copy will be much faster than the original write

@danlabici
Copy link
Collaborator

danlabici commented Mar 4, 2019

Definitely worth exploring.
Thanks for the suggestion!

@danlabici
Copy link
Collaborator

@bccrisan Please try to make a proof of concept based on aki's suggestion.

@lundjordan
Copy link
Contributor

Sounds like you want some logic to make each run atomic (either complete or revert on error).

@aki's suggestion probably would be the easiest. One thing to consider is how often this would happen. If your use case is a human interrupting the script, I think it's not worth fixing given the md and json is all in version control. You can just rollback to an earlier rev or clean your staging environment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working core Issue that affect our core functionality
Projects
None yet
Development

No branches or pull requests

7 participants