Created
September 5, 2017 13:32
-
-
Save JosephRedfern/110be0479aaf8c986569bb23aef43ba5 to your computer and use it in GitHub Desktop.
produces "TypeError: can't pickle _thread.lock objects" under W10 w/ Python 3.6.2.
This file contains 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 time | |
import random | |
from queue import Queue | |
from multiprocessing import Process | |
import os | |
def produce_data(q): | |
print("[+] Producer thread started (PID: {})".format(os.getpid())) | |
while True: | |
duration = random.randint(0, 1000) | |
value = random.randint(0, 1000) | |
time.sleep(duration/1000.0) | |
q.put(value) | |
def process_data(q): | |
print("[+] Processor thread started (PID: {})".format(os.getpid())) | |
while True: | |
data = q.get() | |
print("{} -- that's numberwang!".format(data)) | |
if __name__ == '__main__': | |
q = Queue() | |
dp_proc = Process(target=produce_data, args=(q,)) | |
pd_proc = Process(target=process_data, args=(q,)) | |
dp_proc.start() | |
pd_proc.start() | |
# blocks forever | |
dp_proc.join() | |
pd_proc.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oops. Should be using
multiprocessing.Queue
notqueue.Queue
!