Hello,

First, I would appreciate if anyone can help with this issue I'm
facing.  Second, I am new to web2py, and not a programmer by
profession.  I have written an application for conducting tournaments
with the ultimatum game - a simple bargaining game.  The problem: it
seems to work fine running on my personal machine via localhost, but
when hosted (WebFaction) the application locks up if a particular link
is clicked more than once.

The details... one player must wait for information from another
player.  I'm using a database poll as a means for the waiting player
to know when information is available.  While the polling takes place,
the player's view is still presenting an active link.  Clicking this
link more than once causes a problem.  As I mentioned above, the
server-side pattern I've implemented works when running locally, but
seems to fail in a hosted situation.  Oh, since I'm less familiar with
javascript than Python I was trying for a server-side solution.  I
have started reading about jQuery but have not yet been able to
get .one() working to prevent extra clicks.  Thank you in advance!

The relevant code...

The view and controller function from which the player clicks to begin
the database poll...

def responder_enter_game():
    """
    The point at which the responder enters the game.
    The view will hang on this page as the database polling is
processed in
    the next page called from the view.
    Prior to calling this function, session.first_time must be set to
True!
    """
    return dict()

Note: I using the default layout.html

{{extend 'layout.html'}}
<h3>You are playing as a responder in this game...</h3>
<ul>
  <li>{{=A(B(T("Click to enter game")), _href=URL('responder_waits'))}}
</li>
  <li>{{=T('Please be patient...')}}</li>
  <li>{{=T('You will leave this page after a proposal has been
offered.')}}</li>
</ul>

{{extend 'layout.html'}}
<h3>Waiting for a response... please be patient</h3>
{{redirect(URL('game_results_proposer'))}}

Here is the controller code for responder_waits...

def check_proposal_confirmed():
    """
    The resopnder's view is hanging on respnder_enters_game() until
proposal_confirmed is True.
    The function time.sleep(0.5) causes a 0.5 second delay between
    polls on the database.
    """
    proposal_confirmed = False

    while not proposal_confirmed:
        proposal_confirmed =
db.games[session.game_id].proposal_confirmed
        time.sleep(0.5)

def responder_waits():
    """
    The responder is waiting for a proposal confirmation to be found
in the database
    """
    if session.first_time:                  ## The first time the
player clicks the link processing continues
        session.first_time = False      ## The first time has passed
        check_proposal_confirmed()   ## This function holds until the
proposer confirms a proposal
    else:                                         ## Any additional
time the player clicks the link no action is taken
        pass

    return dict()

Reply via email to