python - How do I multithread this function? What's wrong with my current syntax? -
my current, single threaded call function looks this:
deepdream(net, frame, end=layersloop[frame_i % len(layersloop)],iter_n = 5) which works fine single-threaded.
but want make multithreaded. right have code looks this:
if threading.activecount()>10: frame = deepdream(net, frame, end=layersloop[frame_i % len(layersloop)],iter_n = 5) else: t = threading.thread(target=deepdream, args=(frame,end=layersloop[frame_i % len(layersloop)],iter_n = 5))) threads.append(t) t.start() which makes stay less 10 threads. (so if thread count greater 10, single thread call. if it's less 10 active threads, single threaded call.
but reason, error:
file "3_dreaming_time.py", line 142 t = threading.thread(target=deepdream, args=(frame,end=layersloop[frame_i % len(layersloop)],iter_n = 5))) ^ syntaxerror: invalid syntax i'm new python , don't understand what's wrong syntax. help?
ps. want variable frame equal return of deepdream function. in singlethread.
you're passing keyword arguments threading.thread() target invocation incorrectly. try instead:
t = threading.thread(target=deepdream, args=(frame,), kwargs=dict(end=layersloop[frame_i % len(layersloop)], iter_n=5))
Comments
Post a Comment