title: How to run 2 different processes with python at the same time?
body: <p>I have a looping script , to get infos on a french site. It looks like this :</p>
  
  <pre><code>def getInfos(a,b,c)
  
  def MyLoop(filename)
  </code></pre>
  
  <p>in which i call getinfos via</p>
  
  <pre><code>def MyLoop(filename) 
      values = getInfos()
  </code></pre>
  
  <p>And It works well. But sometimes, the script slows down and finally stops. 
  So i tried several modules with different ideas in mind.
  The first module ; Signal. But (subjectively) interesting functions are not avalaible on windows.
  However, i tried to stimulate execution when it's frozen:</p>
  
  <pre><code>def reboot(signal, frame):
      print '??FROZEN??'
      time.sleep(1)
      #sys.exit(0)
  signal.signal(signal.SIGINT, reboot)      
  </code></pre>
  
  <p>As you can see i tried <code>sys.exit(0)</code>, but too abrupt, and i'm not sur of what's really done. Anyway... after a two-hour loop, i get no answer with this transformed "<code>keyboard interrupt</code>" function.</p>
  
  <p>Then i tried to limit execution time.
  So i found : <code>Multiprocessing</code>, <code>pp</code>, <code>signal (~5%avalaibleOnWindows)</code>.
  The first one opened 30 or 40 other brackgrounded python processes.
  The second one, pp, do not allow to paralelize two differents function. No it does ?</p>
  
  <p>Do you have something that could work for me ? or at least, something i can try, to figure me out where the first step is ?</p>
  
  <p>14 months later...
  Finally, surely by lack of experience, i decided to use multiprocessing. Making some bots as executors, and 1 of them as checker/killer of the possibly frozen external process.</p>
  
  <p>First, the multoprocessing approach:</p>
  
  <pre><code>#my_mp.py
  import multiprocessing as mp
  import actions as ac
  bot_ids = list('ab')
  if __name__ == '__main__':
      jobs = []
      for bot_id in bot_ids:
          p = mp.Process(target=ac.Act , args=(bot_id,))
          jobs.append(p)  ;  p.start()
  </code></pre>
  
  <p>Then, what is multiprocessed:</p>
  
  <pre><code>#actions.py
  import time,random,glob,os,psutil
  #________________________
  def check_or_kill(eXe,bTm):
      age_max = 900
      if time.time() - bTm &gt; age_max:
          for proc in psutil.process_iter():
              if  (proc.name == eXe):proc.kill()
      return
  #________________________
  def Act(bot_id):
      checker = random.choice(list('ab'))
      if bot_id not in checker:
          f = open('stTime_%s.txt'%bot_id , 'w')  ;  f.write('%s'%(time.time()))  ; f.close()
          #launch the execution file and then, when it's done :
          os.remove('stTime_%s.txt'%bot_id)
      else:
          #get their inner birthtime.
          while glob.glob('localfolder_path','stTime_*.txt') != []: check_or_kill('soft.exe',birthtime)
      return
  </code></pre>