Category : thread-safety

I have two or more threads instanciated from same class called ‘Player’, sharing memory_buffer. class Player(Thread): def __init__(self, player_number, memory_buffer): super().__init__() self.memory_buffer = memory_buffer self.player_number = player_number self.lock = Lock() def add_data(self, count): with self.lock: self.memory_buffer.add_data(self.player_number, count) def run(self): count = 0 while True: self.add_data(count) count += 1 Where memory_buffer is an object as below: ..

Read more

I was wondering if there was a way to run the tkinter mainloop on a separate thread (not the mainthread) so that the terminal is "free". Let’s say we have a simple GUI: import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.grid() self.createWidgets() def printHello(self): print("Hello") def createWidgets(self): self.quitButton = tk.Button(self, text=’Quit’, ..

Read more