'Python multithreading with PyGame
I am using pygame and trying to setup multiprocessing where some code runs in the background.
I have pygame running from a class:
class UI:
def __init__(self, window_size, world_size, scale = 10, fps = 60):
self.window_size = window_size
self.world_size = world_size
self.scale = scale
self.fps = fps
pygame.init()
self.fpsClock = pygame.time.Clock()
self.Window = pygame.display.set_mode(window_size)
pygame.display.set_caption('RADAR')
def step(self):
# Get inputs
for event in pygame.event.get() :
if event.type == QUIT :
pygame.quit()
sys.exit()
# Processing
# This section will be built out later
# Render elements of the game
self.Window.fill(BACKGROUND)
pygame.display.update()
def run(self):
while True:
self.step()
And my process that I'm trying to run is very simple:
def test():
while True:
print("Hello from a thread!")
In my main function I am calling:
if __name__=="__main__":
ui = UI((700,700),(700,700))
p = Thread(Environment.test())
p.start()
ui.run()
It seems to only run the thread and doesn't actually run the pyGame code. In know python isn't great for multi threading but any suggestions?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
