from multiprocessing import Queue, Process
import time
import backend
command_queue = Queue()
response_queue = Queue()


def start_backend():
    if handler:
        handler.stop()
    handler = Process(target=backend.start, args=(command_queue, response_queue))
    handler.start()


def get_for(url, queue, timeout):
    beginning = time.time()
    result = queue.get(timeout=timeout)
    if result["url"] == url:
        return result["body"]
    else:
        queue.put(result)
        return get_for(url, queue, timeout - (time.time()-beginning))
from multiprocessing import Queue, Process
import time
import backend
command_queue = Queue()
response_queue = Queue()


def start_backend():
    handler = Process(target=backend.start, args=(command_queue, response_queue))
    handler.start()


def get_for(url, queue, timeout):
    beginning = time.time()
    result = queue.get(timeout=timeout)
    if result["url"] == url:
        return result["body"]
    else:
        queue.put(result)
        return get_for(url, queue, timeout - (time.time()-beginning))
Revert "Quit Backend If Running"
Revert "Quit Backend If Running"

This reverts commit a00432191e2575aba0f20ffb1a96a323699ae4fc.

  from multiprocessing import Queue, Process
  import time
  import backend
  command_queue = Queue()
  response_queue = Queue()
  
  
  def start_backend():
-     if handler:
-         handler.stop()
      handler = Process(target=backend.start, args=(command_queue, response_queue))
      handler.start()
  
  
  def get_for(url, queue, timeout):
      beginning = time.time()
      result = queue.get(timeout=timeout)
      if result["url"] == url:
          return result["body"]
      else:
          queue.put(result)
          return get_for(url, queue, timeout - (time.time()-beginning))
Revert "Quit Backend If Running"
## Code Before:
from multiprocessing import Queue, Process
import time
import backend
command_queue = Queue()
response_queue = Queue()


def start_backend():
    if handler:
        handler.stop()
    handler = Process(target=backend.start, args=(command_queue, response_queue))
    handler.start()


def get_for(url, queue, timeout):
    beginning = time.time()
    result = queue.get(timeout=timeout)
    if result["url"] == url:
        return result["body"]
    else:
        queue.put(result)
        return get_for(url, queue, timeout - (time.time()-beginning))
## Instruction:
Revert "Quit Backend If Running"
## Code After:
from multiprocessing import Queue, Process
import time
import backend
command_queue = Queue()
response_queue = Queue()


def start_backend():
    handler = Process(target=backend.start, args=(command_queue, response_queue))
    handler.start()


def get_for(url, queue, timeout):
    beginning = time.time()
    result = queue.get(timeout=timeout)
    if result["url"] == url:
        return result["body"]
    else:
        queue.put(result)
        return get_for(url, queue, timeout - (time.time()-beginning))