Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

loop freezing over mutiple trials of image presentation and keyboard response

Hi, we're running a fairly basic image presentation as a cue to response over two loops of 320 trials each. The experiment will freeze in place randomly (resumes by hitting esc and resuming, but that is not a feasible solution as it would break mri scanner timing). Code for object generation:

number_of_trials = 320  #320 actual 80 for debug

shapes = ["red_square"]*(int(0.3*number_of_trials))	#adding the frequency of red squares proportional to .3?

for colour in ["yellow", "blue", "green"]:

    shapes += ["%s_square"%colour]*(int((0.175/3) * number_of_trials))

shapes += ["yellow_square", "blue_square"]

for shape in ["star", "circle", "triangle"]:

    shapes += ["red_%s"%shape]*(int((0.175/3) * number_of_trials))

shapes += ["red_star", "red_circle"]

for colour in ["yellow", "blue", "green"]:

    for shape in ["star", "circle", "triangle"]:

        shapes += ["%s_%s"%(colour,shape)]*(int((0.35/(3*3) * number_of_trials)))

shapes += ["green_triangle", "blue_triangle", "green_circle", "blue_star"]

lenShapes = len(shapes)/4


timings = []

while lenShapes > 0:

        timings += [1000]

        timings += [1500]

        timings += [2000]

        timings += [2500]

        lenShapes -= 1



print("len of shapes: " + str(len(shapes)))

print("len of timings: " + str(len(timings)))

Code for the loop (first python script) prepare:

global shapes
global timings
shape = shapes.pop()
ISI = timings.pop()

self.experiment.set("trial_shape", shape)
self.experiment.set("trial_ISI", ISI)

second python script prepare:

from openexp.canvas import canvas
canvas_shape = canvas(exp)
canvas_blank = canvas(exp)
path = exp.get_file("stimuli/%s.png"%exp.get("trial_shape"))

second python script run:

from openexp.keyboard import keyboard

# Durations for the two displays
duration_shape = 100
duration_blank = self.experiment.get('trial_ISI')

# Displays are copied from sketchpads. To avoid these
# sketchpads from being shown twice (i.e. once in the 
# normal way, and once in this inline_script), you can set
# their 'Run-if' statement to 'never'.

# Create a keyboard object with a zero timeout to allow
# for continuous polling.
my_keyboard = keyboard(exp, timeout=0)
key = None		#changed from None to 1 to see if this controls allowed responses? perhaps not

# Show the first canvas, and poll the keyboard for the
# specified duration.
show_time_shape =
exp.set('onset_time_shape', show_time_shape)		#trying to get onset time of shape
while self.time() - show_time_shape < duration_shape:
	if not key:
		key, time = my_keyboard.get_key(keylist=[1])

# Show the second canvas, and poll the keyboard for the
# specified duration.       
show_time_blank =
while self.time() - show_time_blank < duration_blank:
	if not key: 
		key, time = my_keyboard.get_key(keylist=[1])

exp.set('response', key)
if key:
	exp.set('response_time', int(round(time-show_time_shape)))
	exp.set('response_time', 0)

followed by a logger.

My guess is that the repeated get_file() calls are causing the issue, so we've tried running with legacy and xpyriment back-ends with garbage collection enabled and disabled, but unsuccessful in getting consistent reliability. If anyone has insight into this issue much app


  • If you get stuck in a while loop, you get the impression of freezing. So, possible it lies somehow there?

    What about putting key=None before the second while loop?

    Not sure, whether this helps you out, but worth a try.



  • Hi @kazald,

    Could you upload the scripts embedded in the experiment you use? Perhaps with irrelevant parts removed? On the first glance I can't see obvious mistakes, but also code that could be improved.

    First part of the debugging process would be to identify at which line exactly the experiment stalls. The easiest way would be to include regular print statements in your experiment and observe when a delay occurs.


    Buy Me A Coffee

  • Hi Eduard, thank you for your reply. Here is a copy of the experiment, per my notes in the other posted question referencing this problem, the issue seems to lie with the while loop on line 9 of the run tab for the origshowandcollect python script within the new_loop. This was determined by the experiment freezing while showing a shape, so it is not within the second while loop which just shows a blank canvas as the stimulus interval. Commenting out the keyboard response collection relevant code results in the same stoppage, our lab runs on macs, so we're seeing CPU usage of python via the activity monitor.

  • Hi,

    attached a streamlined version of your experiment. Perhaps that helps. However, as I said earlier, I couldn't find anything intrinsically wrong with your code and I also have not experienced any freezing. Perhaps this is related to your setup? Try to pilot the experiment at the scanner and maybe it will run there just fine.


    Buy Me A Coffee

  • Hi Eduard, the streamlining of the code does seem to have helped, project isn't freezing any more. Thank you for your help, I must admit I am confused as to why altering the if/then statements outside the loop fixed the problem. I guess if anyone else is referencing this for a similar problem, I would suggest checking logic statements for possible cases where those statements aren't getting resolved.

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games