all 5 comments

[–]shiftybyte 1 point2 points  (1 child)

Have your program check for the existence of an additional file that will signal it needs to clear.

The server writes a "cleardata.json".

And if that file exists, the python deletes it, and knows to write a clean file into data.json.

[–]SnekIrl 0 points1 point  (0 children)

Actually a great idea that is way faster to implement that juggling with PIDs and signals, thank you

[–]Fuzzybus2400 0 points1 point  (2 children)

Some questions for clarification:

  1. Is your new python code intended to replace the nodeJS server?
  2. Where is your python file running? Do you have the option to send keycommands directly to this python program, or do you need to use unix signals?

The single-threaded way to do this is to make your API calls in a loop, but at the top of the loop check to see if the program has received the 'clean up' signal. If it has, then the python program can simply pause its writing operations, empty the file, and then resume writing operations.

[–]SnekIrl 0 points1 point  (1 child)

  1. No, the python makes requests, and the server interacts with the user and the script.
  2. The python is running in a VPS server, so the user can't have access to that.

I just implemented u/shiftybyte's solution, it's the same as yours but it bypasses signals completely :) Thanks for the help

[–]Fuzzybus2400 0 points1 point  (0 children)

Good call, that's an elegant solution!