Timeouts on wait pages

915 views
Skip to first unread message

Raffael Huber

unread,
Apr 1, 2021, 10:55:50 AM4/1/21
to oTree help & discussion
Hello everyone,

I have a question regarding timeouts on wait pages. 

I exactly followed the instructions in the Docs (https://otree.readthedocs.io/en/latest/multiplayer/waitpages.html#timeouts-on-wait-pages), but it doesn't seem to work - the subjects wait as long as there are less than 3 players to form a group and do not proceed as single-player groups after the defined time. 

I can see that the variable wait_page_arrival is correctly set with time.time() in the app before and I save the variable also in PARTICIPANT_FIELDS  exactly like I do for all other variables for which it works.

Are there any other common mistakes I can make?

Is it possible that the wait page does not refresh automatically in otree 5 and does not re-executes group_by_arrival_time_method from time to time? 

I assign roles which works well. Is it possible that this conflicts with the timeout on the waitpage in any way?

Any hint what it could be would be much appreciated!

Best




PZ

unread,
Apr 7, 2021, 7:24:15 AM4/7/21
to oTree help & discussion

Hey, the following code should work:
(the omitted code parts are the ones you find in every app)

Settings


PARTICIPANT_FIELDS = ["wait_page_arrival"]

First App

import time
# PAGES
class MyPage(Page):
    @staticmethod
    def before_next_page(player: Player, timeout_happened):
        player.participant.wait_page_arrival = time.time()

Second App

import time

class Constants(BaseConstants):
    players_per_group = 2

class Subsession(BaseSubsession):
    @staticmethod
    def group_by_arrival_time_method(subsession, waiting_players):
        if len(waiting_players) >= 2:
            return waiting_players[:2]
        for player in waiting_players:
            if waiting_too_long(player):
                # make a single-player group.
                return [player]

class Group(BaseGroup):
    pass

class Player(BasePlayer):
    pass

# Function
def waiting_too_long(player):
    participant = player.participant
    return time.time() - participant.wait_page_arrival > 5

# PAGES
class ResultsWaitPage(WaitPage):
    group_by_arrival_time = True

class MyPage(Page):
    pass

page_sequence = [ResultsWaitPage, MyPage]  # Waitpage must be the first page in the app!

Chris @ oTree

unread,
Apr 7, 2021, 7:42:09 AM4/7/21
to oTree help & discussion
Almost ;) group_by_arrival_time_method should be a top-level function, rather than Subsession method:

class Subsession(BaseSubsession):
    pass

def group_by_arrival_time_method(subsession, waiting_players):
    if len(waiting_players) >= 2:
        return waiting_players[:2]
    for player in waiting_players:
        if waiting_too_long(player):
            # make a single-player group.
            return [player]




Chris @ oTree

unread,
Apr 7, 2021, 7:44:20 AM4/7/21
to oTree help & discussion
(In the new format, there are no methods on Player/Group/Subsession.)

Raffael Huber

unread,
Apr 7, 2021, 10:21:13 AM4/7/21
to oTree help & discussion
Thank you, PZ and Chris!

Tbh, I tried exactly this line of code among other codes but apparantly I doubted myself too early and never waiting long enough to see it work. I think the same code doesn't work without "group_by_arrival_time = True" though.

Again, thank you!

Raffael Huber

unread,
May 22, 2021, 7:10:14 AM5/22/21
to oTree help & discussion
Update: After more extensive testing, I came across some minor inconvinience with this method. When a player leaves the browser while waiting for other group members, this player does not count to the pool of players to form a group. This is desired because the player is not active anymore. However, by re-opening the link anytime later, the participant is able to continue with the study at this stage. Usually, the timeouts ensure that inactive players eventually drop out of the experiment. In this case, when leaving the browser, a player can essentially pause the experiment for an unlimited amount of time and then proceed whenever later. 

I think one work around is to monitor the study and manually click on the link of the participant to make the player proceed and then let the time run out. Is there an automated way too to do this?

Chris @ oTree

unread,
May 22, 2021, 8:57:11 AM5/22/21
to oTree help & discussion
If that's what you want, then you can omit group_by_arrival_time_method entirely.  That is already the default behavior of group_by_arrival_time. Players who abandon the wait page are excluded from grouping.

Raffael Huber

unread,
May 23, 2021, 2:54:42 AM5/23/21
to oTree help & discussion
Apologies, my message might have been ambigous. I want to match sufficient active players to a group and let active players proceed alone after a specified time when there are not sufficient active players to form a group. I can achieve that by  group_by_arrival_time_method. Ideally in addition, I want to advance inactive players (i.e. players that closed the browser) after the specified time. Inactive players should always advance alone independent of the number of active players in the same stage. Right now, the time for inactive players does not run out, they can open the link later and then continue alone without any timeout. 

Rok

unread,
Jun 1, 2021, 3:28:25 PM6/1/21
to oTree help & discussion
Hello,

Your problem seems to be with timeouts not happening.

Timeouts for participants that dont have a page open in the browser only work in production mode. (not devserver) If you're using production mode and still have issues with timeouts not happening, it might be sqlite problem. Switch to using Postgres instead. (You can check if it's an sqlite problem by checking error logs, if it says anything about database being unreadable/locked etc, you should definitely switch to Postgres)

Best Regards,
Rok

Reply all
Reply to author
Forward
0 new messages