Thanks.
I have added sys.exit() after pygame.quit() but IBus still crashes (not
every time but generally after the second test).
Similar bugs have been reported
(https://bugs.launchpad.net/ubuntu/+source/ibus/+bug/945471) so I don't
think it is related to python.
The thing is that when IBus crashes my program works better. To
summarize my program works this way:
for stim in trials:
# Display Stimulus & wait
display_stim(stim, size)
pygame.time.wait(DISPLAY_DURATION)
# Display response screen and wait for response
response, rt = display_response()
# Wait before next stimulus
screen.fill(bg)
pygame.display.flip()
pygame.time.wait(PAUSE_BETWEEN_TRIALS)
The functions display_stim and display_response use
pygame.display.flip(). The response must be displayed until the user
presses some response (1, 2, 3, etc.) or a timeout occurs or the user
presses 'ESC' to quit the program. To ignore previous input, I clear the
event loop before waiting for input.
The function display_response works like this:
# Clear screen
screen.fill(bg)
# Draw response
[...]
# Update screen
pygame.display.flip()
t_display = pygame.time.get_ticks()
pygame.event.clear()
pygame.time.set_timer(TIMEOUT_EVENT, TIMEOUT)
Respdone = False
while not Respdone:
for ev in pygame.event.get():
t_reponse = pygame.time.get_ticks()
if (ev.type == pygame.locals.KEYDOWN):
if ev.key == pygame.locals.K_ESCAPE:
raise Exception
key_value = ev.unicode;
if key_value in VALID_ANSWERS:
Respdone = True
[find the response pressed]
break
if (ev.type == TIMEOUT_EVENT):
# Disable this event
pygame.time.set_timer(TIMEOUT_EVENT, 0)
Respdone = True
resp = TIMEOUT_VALUE
rt = float("inf")
break
return resp, rt
When Ibus is running if I press a key (say 1) after the response screen
but before the next stimulus this key is taken as the response
(therefore the measured reaction time is a few milliseconds).
As far as I can test, when IBus crashes, the behaviour is correct.
Maybe my program is incorrect but I can't figure what's wrong (the only
problem that I see in this version is that I should disable the timeout
when a response is detected).
That's why I think IBus is interfering in my program. I don't really get
what IBus is used for but I was thinking that trying to not kill it with
my program is good. Apparently the problem is deeper than what is was
thinking. The most important thing is to have my program working.
Any idea?
Mathieu
Le 12/04/2013 20:45, Elias Benevedes a écrit :
I always include 'import sys' at the top, so that after I call
pygame.quit(), I can call sys.exit() which can sometimes stop the
program from hanging.
On Fri, Apr 12, 2013 at 8:04 AM, Mathieu Dubois <mathieu.dubois@xxxxxxxx
<mailto:mathieu.dubois@xxxxxxxx>> wrote:
Hello,
I am using Pygame (1.9.1release) under Ubuntu (12.04). I have
noticed that when sometimes when I quit my program (with
pygame.quit()) the Ibus (which is related to input handling)
component crashes.
My program is essentially a psychological experiment: it displays
some stimuli and wait for user input. If the user presses the 'ESC'
key, the program raises an exception. The pygame.quit() function is
called in the finally block.
I wanted to know if this is known issue or if I am doing something
wrong. I can try to work on a MWE if needed.
Thanks in advance,
Mathieu
--
"The validity of internet quotes are getting sketchy nowadays"
-Abraham Lincoln