title: running two interdependent while loops in python?
body: <p>For a web-scraping analysis I need two loops that run permanently, one returning a list with websites updated every x minutes, while the other one analyses the sites (old an new ones) every y seconds. This is the code construction that exemplifies, what I am trying to do, but it doesn't work: <strong>Code has been edited to incorporate answers and my research</strong></p>
  
  <pre><code>from multiprocessing import Process
  import time, random
  
  from threading import Lock
  from collections import deque
  
  class MyQueue(object):
      def __init__(self):
          self.items = deque()
          self.lock = Lock()
  
      def put(self, item):
          with self.lock:
              self.items.append(item)
  # Example pointed at in [this][1] answer
      def get(self):
          with self.lock:
              return self.items.popleft()
  
  def a(queue):
      while True:
          x=[random.randint(0,10), random.randint(0,10), random.randint(0,10)]
          print 'send', x
          queue.put(x)
          time.sleep(10)
  
  
  def b(queue):
      try:
          while queue:
              x = queue.get()
              print 'recieve', x
              for i in x:
                  print i
              time.sleep(2)
      except IndexError:
          print queue.get()   
  
  
  
  if __name__ == '__main__':
      q = MyQueue()
      p1 = Process(target=a, args=(q,))
      p2 = Process(target=b, args=(q,))
      p1.start()
      p2.start()
      p1.join()
      p2.join()
  </code></pre>
  
  <p>So, this is my first Python project after an online introduction course and I am struggling here big time. I understand now, that the functions don't truly run in parallel, as b does not start until a is finished ( I used <a href="https://stackoverflow.com/a/21045587/2822564">this</a> answer an tinkered with the timer and while True). <strong>EDIT:</strong> Even after using the approach given in the answer, I think this is still the case, as the <code>queue.get()</code> throws an IndexError saying, the deque is empty. I can only explain that with process a not finishing, because when I print queue.get()
  immediately after .put(x) it is not empty.</p>
  
  <p>I eventually want an output like this:</p>
  
  <pre><code>send [3,4,6]
  3
  4
  6
  3
  4
  send [3,8,6,5] #the code above gives always 3 entries, but in my project 
  3              #the length varies
  8
  6
  5
  3
  8
  6
  .
  .
  </code></pre>
  
  <p>What do I need for having two truly parallel loops where one is returning an updated list every x minutes which the other loop needs as basis for analysis? Is Process really the right tool here? 
  And where can I get good info about designing my program. </p>