I have a program that should run forever. Here is what I am doing:
from myfuncs import do, process
class Worker(multiprocessing.Process):
def __init__(self, lock):
multiprocesing.Process.__init__(self)
self.lock = lock
self.queue = Redis(..) # this is a redis based queue
self.res_queue = Redis(...)
def run():
while True:
job = self.queue.get(block=True)
job.results = process(job)
with self.lock:
post_process(self.res_queue, job)
def main():
lock = multiprocessing.Semaphore(1)
ps = [Worker(lock) for _ in xrange(4)]
[p.start() for p in ps]
[p.join() for p in ps]
self.queue and self.res_queue are two objects that work similar like python stdlib Queue but they use Redis database as a backend.
Function process does some processing to the data that job carries( mostly html parsing ) and returns a dictionary.
Function post_process writes the job to another redis queue by checking some criteria (only one process at a time can check for the criteria that's why the lock). It returns True/False.
The memory used by the program everyday is increasing. Can somebody figure out what is going on?
Memory should be free when job get outs of scope in the run method correct?