multithreading - Python Multiprocessing Queue: Reading queue from another module -
i have issue reading multiprocessing queue function reading queue being called module.
below class containing function start thread runs function_to_get_data
. class resides in own file, call one.py. function_to_get_data
in file, two.py , infinite loop puts data queue (code snippet further down). contains function read queue. queue q
defined globally @ beginning.
import multiprocessing 2 import function_to_get_data q = multiprocessing.queue() class poller: def startpoller(self): pollerthread = multiprocessing.process(target=module_to_get_data,args=(q,)) pollerthread.start() def getpoller(self): if q.empty(): print "queue empty" else: pollresqueue = q.get() q.put(pollresqueue) return pollresqueue if __name__ == "__main__": startpoll = poller() startpoll.startpoller()
below snippet function_to_get_data
:
def module_to_get_data(q): while 1: # performs actions # q.put(data_from_actions)
i have module, three.py, requires data queue , requests calling function initial class:
from 1 import poller externalpoller = poller() data_this_module_needs = externalpoller.getpoller()
the issue queue empty.
i should add function in three.py called thread in one.py post web page:
def post(data): data = web.input() if data == 'start': thread_two = multiprocessing.process(target= function_in_three_py, args=(q,)) thread_two.start()
if use python command line , enter 2 poller functions , call them, data queue no problem.
Comments
Post a Comment