M
M
miki1312016-08-03 14:22:59
Python
miki131, 2016-08-03 14:22:59

How to make a minute-by-minute accounting of the script's work?

There is a certain python script that takes a settings file as input and does its job perfectly.
I run it on the command line like this. The
python script.py --config user1.json
task is to make it possible to launch it through the web interface and taking into account the time that the script will run.
Those. each user can start/stop the script, and see in his panel how many minutes the script worked in total.
I think to do with NodeJS - for each user, launch a process that will manage the python process

var workerProcess = child_process.spawn('python', ['script.py', '--config', file]);

Would love to hear other implementations.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
Philipp, 2016-08-03
@zoonman

time -p python script.py --config user1.json

I
Ilya, 2016-08-03
@FireGM

A crutch in the form of a record of the start time of the script in the database.
And the ending too. And in general, more logs can be done.

A
asfhyg4873gfdj, 2016-08-04
@asfhyg4873gfdj

You can create a separate thread in which, in a cycle, every minute, write to a file or where you need how long the program works.

K
Kamo Petrosyan, 2016-08-11
@Haikson

What is not clear is this: does the user launch the process and wait for it to complete? Or is the state of the script checked every N seconds? The first case is dangerous because the script can run longer than the timeout of the sending server (nginx, apache). But if this is excluded, then it is worth storing the script startup time in the session / cookies and after completion, calculate the difference. In the second case, you can create a lock file to protect against re-running the script. Let's say with the name user1.lock . You can record the start time in it. Or, do not write to the file, but write to the session variable and check for the presence of a lock file every N seconds. And again, arithmetic comes into play. There are many options, but they all boil down to storing the launch time somewhere. I do not advise to write to a DB. Expensive. It is better to create-delete small files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question