5

I have a script which calculates a variable every second (my program read an output of script bash and interprete the datas every second). Is a way exist to detect if this var changes?

Here is a part of my code, the text is ffmpeg or avconv output, read from a vte terminal:

#Terminal
def terminal(self):
        self.v = vte.Terminal()
        self.v.connect ("child-exited", lambda term: self.verif(self, my_class))
        self.v.connect('contents-changed', self.term_output)
        [...]    
def term_output(self, my_class, donnees=None):
        text = str(self.v.get_text(lambda *a: True).rstrip())
        [...] # decode the text
        print "time", self.time
        print "duration", self.duration

The return in the vte terminal (avconv output):

Duration: 00:00:23.00, start: 0.100511, bitrate: 0 kb/s
Output #0, matroska, to '/media/guillaume/XT/Telechargements/uzz/la_qualite_de_l_air_1000019643.mkv':
Press [q] to stop, [?] for help
frame=  589 fps=115 q=-1.0 Lsize=    2191kB time=00:00:23.79 bitrate= 754.3kbits/s
FIN DU TRAITEMENT
Votre Fichier Final Est:
/media/guillaume/XT/Telechargements/uzz/la_qualite_de_l_air_1000019643.mkv

Example of output (it's time and duration from vte output):

time 5.1
duration 23.0
time 6.1
duration 23.0
time 9.1
duration 23.0
time 14.1
duration 23.0
time 14.1
duration 23.0
time 16.1
duration 23.0
time 18.1
duration 23.0
time 19.1
duration 23.0
time 21.1
duration 23.0
time 23.1
duration 23.0
time 23.1
duration 23.0
time 23.1
duration 23.0
time 23.1
duration 23.0
time 23.1
duration 3960.0 # detect this change? (correspond to a second output of avconv)
time 1.1
duration 3960.0
time 7.1
duration 3960.0
time 10.1
duration 3960.0
time 20.1
duration 3960.0
time 20.1
duration 3960.0 
7
  • Can you please include a program which has this behaviour and explain us the problem clearly? Commented Dec 20, 2014 at 14:12
  • It's a little complicated to explain, my program read an output of script bash and interprete the datas every second Commented Dec 20, 2014 at 14:14
  • I am sorry without seeing the program we cannot help you fix the problem :( Commented Dec 20, 2014 at 14:19
  • Ok I will try to add a part my code Commented Dec 20, 2014 at 14:20
  • I dont't think it's more clearly like this ? Commented Dec 20, 2014 at 14:43

1 Answer 1

3

Add a flag variable (global or local depending upon the required scope).

Assign the value to flag in the beginning / first loop.

Compare the value of this flag against the variable and if it changes, (either a signal or a print whatever you need).

time_val = 'init';

def term_output(self, my_class, donnees=None):
    text = str(self.v.get_text(lambda *a: True).rstrip())
    [...] # decode the text
    if (time_val == 'init'):
        time_val = self.time
    if self.time != time_val:
        print "The value of time has changed from " + str(time_val) + " to " + str(self.time)
    print self.time
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.