作为背景,我正在运行 Debian Lenny,并且已经在 GNOME 和 Fluxbox 上进行了尝试。
无论如何,我一直在研究如何在桌面上绘图,我在这里找到并尝试了这段代码:http: //blog.prashanthellina.com/2007/08/24/drawing-on-your-desktop/
它工作得很好,除了终止它(通过按控制 C),X 失去了创建新窗口的能力。
我原以为问题可能是 pygame 没有释放一些资源,所以我添加了一段代码来捕获 kill 信号,给了我以下信息:
"""
Run the following command in the shell before executing this script
export SDL_WINDOWID=`xwininfo -root|grep "id:"|sed 's/^.*id: //'|sed 's/ (.*$//'`
"""
import pygame
import sys
import random
import time
import signal
pygame.init()
window = pygame.display.set_mode((1280, 1024))
screen = pygame.display.get_surface()
def handle_sigint(signum, frame):
"""I want to ensure resources are released before bailing."""
print("SIGINT received.");
pygame.display.quit()
pygame.quit()
sys.exit(0)
# Set handler to catch C^C Interupts
signal.signal(signal.SIGINT, handle_sigint)
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit(0)
x = random.choice(range(640))
y = random.choice(range(480))
radius = random.choice(range(100))
col_r = random.choice(range(255))
col_g = random.choice(range(255))
col_b = random.choice(range(255))
time.sleep(.03)
rect = pygame.draw.circle(screen, (col_r, col_g, col_b), (x,y), radius)
pygame.display.update(rect)
所以我又试了一次。中断处理程序中的打印语句告诉我,当我退出时处理程序确实运行了,但我仍然遇到同样的问题。更有趣的是,X 在运行时没有任何问题。只有在终止它之后。
可能有人知道发生了什么,以及我可以做些什么来修复代码,这样它就不会破坏我的 X 会话?提前致谢。