I don't know why I'm having such a problem with this, basically, I want to have a Queue that is constantly running during the program called "Worker" this then works, however, every 10 seconds or so.. Another method called "Process" comes in and processes the data. Let's assume the following, data is captured every 10 seconds.. (0, 1, 2, 3, ..... n) and then the "Proces" function receives this, processes the data, ends, and then the "Worker" goes back to work and does their job until the program has ended.

I have the following code:

import multiprocessing as mp
import time

DELAY_SIZE = 10

def Worker(q):
    print "I'm working..."

def Process(q): 
    print "I'm processing.."

queue = mp.Queue(maxsize=DELAY_SIZE)
p = mp.Process(target=Worker, args=(queue,))

p.start()

while True:
  d = queue.get()
  time.sleep(10)
  Process()

In this example, it would look like the following:

I'm working...
I'm working...
I'm working...
...
...
...
I'm working...

I'm processing...
I'm processing...
I'm processing...
...
...

I'm working..
I'm working..

Any ideas?

This works per your example. However you don't have a queue.put() so you won't get anything from the get() call. I don't think that is what you want however. Look up shared data perhaps a dictionary or list would be easiest to understand depending on the size of the data. Also please try to conform to the Python Style Guide (CamelCase is for classes, lower_case_with_underscore for functions) as it makes you code easier for others to understand.

import multiprocessing as mp
import time

DELAY_SIZE = 1

def Worker(q):
    sleep_for = DELAY_SIZE / 2.0
    for ctr in range(10):       
        print "I'm working... %s"  % (ctr)
        time.sleep(sleep_for)

def Process(): 
    print "          I'm processing.."

queue = mp.Queue(maxsize=DELAY_SIZE)
p = mp.Process(target=Worker, args=(queue,))
p.start()

while p.is_alive():
  time.sleep(DELAY_SIZE)
  Process()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.