import subprocess, threading s = 'say hello world' num = 3 while num > 0: if 'say' in s: p = subprocess.Popen('date', shell = True, stdout = subprocess.PIPE) output = p.communicate()[0] print output else: print ('no') num=num-1
А нужно только 3 раза.