python - running 2nd pygame program (for 2nd display) in 2nd SSH terminal pauses until ^C is pressed -
i have 2 displays on raspberry pi 2 running jessie: (default) hdmi display, , adafruit pitft lcd.
i can start pygame programs independently in 2 ssh terminals, 2 different displays, except 2nd 1 run pauses until hit ^c.
using ssh on mac, can run 'count-to-50' pygame program on either 1 fine. (the difference lcd version sets 2 env variables redirect pygame lcd screen.)
if open 2 ssh terminals, , try run both python programs, second program starts running if press control-c.
what need differently second program starts running without first having press control-c?
i'm not sure if "linux" device setup issue, "python" code issue?
here's 2 simple programs:
# count_on_lcd.py import pygame, time, os # on raspberry pi sends lcd screen os.environ['sdl_videodriver'] = 'fbcon' os.environ["sdl_fbdev"] = "/dev/fb1" pygame.init() screen = max(pygame.display.list_modes()) surface = pygame.display.set_mode(screen) surface.fill(pygame.color(0,0,0)) pygame.display.update() font_big = pygame.font.font(none, 150) in range(50): print (i) surface.fill(pygame.color(128,0,0)) text_surface = font_big.render('%s'%i, true, (255,255,255)) rect = text_surface.get_rect(center=(50,50)) surface.blit(text_surface, rect) pygame.display.update() time.sleep(1) surface.fill(pygame.color(0,128,0)) pygame.display.update() time.sleep(1)
and
#count_on_hdmi.py import pygame, time # on raspberry pi hdmi screne default pygame.init() screen = max(pygame.display.list_modes()) surface = pygame.display.set_mode(screen) surface.fill(pygame.color(0,0,0)) pygame.display.update() font_big = pygame.font.font(none, 150) in range(50): print (i) surface.fill(pygame.color(128,0,0)) text_surface = font_big.render('%s'%i, true, (255,255,255)) rect = text_surface.get_rect(center=(50,50)) surface.blit(text_surface, rect) pygame.display.update() time.sleep(1) surface.fill(pygame.color(0,128,0)) pygame.display.update() time.sleep(1)
on mac, open 2 ssh terminals raspberry pi.
in first ssh terminal:
$ sudo python count_on_lcd.py (starts running normally)
in second ssh terminal:
$ sudo python count_on_hdmi.py (pauses until type ^c)
it same thing regardless order start 2 programs... first command invoke runs immediately, second command invoke requires ^c before start running.
this seems issue pygame.init() not playing nicely if itls running in separate ssh terminal.
i found solution on so. it's not pretty works.
only modified pygame requires keyboard interrupt init display
from signal import alarm, signal, sigalrm, sigkill def init_pygame(surf): # section unbelievable nasty hack - reason pygame # needs keyboardinterrupt initialise in limited circs (second time running) class alarm(exception): pass def alarm_handler(signum, frame): raise alarm signal(sigalrm, alarm_handler) alarm(3) print("step 2 ") try: pygame.init() screen = max(pygame.display.list_modes()) surf = pygame.display.set_mode(screen) alarm(0) except alarm: raise keyboardinterrupt return (surf)
Comments
Post a Comment