python - How to avoid multiple running instances of the same function
<p>In my python script I have a <code>core dumped</code>, and I think it's because the same function is called twice at the same time.</p>

<p>The function is the reading of a Vte terminal in a gtk window</p>

<pre><code>def term(self, dPluzz, donnees=None):
    text = str(self.v.get_text(lambda *a: True).rstrip())
    [...]
    print "Here is the time " + str(time.time())

def terminal(self):    
    self.v = vte.Terminal()
    self.v.set_emulation('xterm')
    self.v.connect ("child-exited", lambda term: self.verif(self, dPluzz))
    self.v.connect("contents-changed", self.term)
</code></pre>

<p>Result:</p>

<pre><code>Here is the time 1474816913.68
Here is the time 1474816913.68
Erreur de segmentation (core dumped)
</code></pre>

<p>How to avoid the double executing of the function?</p>

<p>The double execution must be the consequence of the <code>contents-changed</code> event triggering twice.</p>

<p>You could just check in your <code>term</code> function whether it has already been executed before, and exit if so.</p>

<p>Add these two lines at the start of the <code>term</code> function:</p>

<pre><code>    if hasattr(self, 'term_has_executed'): return
    self.term_has_executed = True
</code></pre>

python function