Created
September 21, 2015 20:16
-
-
Save samuell/4b264822010e1e158c38 to your computer and use it in GitHub Desktop.
multiprocessing_queue_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing as mproc | |
# ------------------------------------------------------------------ | |
def lower(qin, qout): | |
while True: | |
s = qin.get() | |
if s is None: | |
#print 'Exiting %s ...' % mproc.current_process().name | |
qin.task_done() | |
qout.put(None) | |
break | |
else: | |
qout.put(s.lower()) | |
def queuetest(): | |
#mproc.log_to_stderr(logging.DEBUG) | |
qin = mproc.JoinableQueue(maxsize=16) | |
qout = mproc.JoinableQueue(maxsize=16) | |
p = mproc.Process(target=lower, args=[qin, qout]) | |
p.start() | |
for s in ['Hej', 'San', 'Hopp', 'San']: | |
qin.put(s) | |
qin.put(None) | |
p.join() | |
while True: | |
s = qout.get() | |
if s is None: | |
qout.task_done() | |
break | |
print s | |
# ------------------------------------------------------------------ | |
if __name__ == '__main__': | |
queuetest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment