Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_parallel_pixel_multiprocessing.py -- fastest in Python said to bypass GIL, especially when compiled... but maybe still much slower than a C variant.
- from Tkinter import *
- import time
- import random
- from PIL import Image, ImageTk
- from multiprocessing import Pool, cpu_count
- root = Tk()
- root.title("Y-Axis-Parallel_Pixels")
- root.geometry("120x120")
- wi = 120
- he = 120
- w = Canvas(root, width=wi, height=he)
- w.pack()
- xy = [y for y in range(he)]
- def thread_process(y):
- return [(0,random.randrange(y*2+15, 255),0) for x in range(wi)]
- if __name__ == '__main__':
- pool = Pool(processes=(cpu_count() - 1))
- img = Image.new( 'RGB', (wi,he))
- while 1:
- p = pool.map(thread_process, xy)
- data = []
- for d in p:
- data.extend(d)
- img.putdata(data)
- imgTk = ImageTk.PhotoImage(img)
- ### saw no glitches
- #time.sleep(0.02)
- w.create_image(0, 0, anchor=NW, image=imgTk)
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement