Doubt with wx.CallAfter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • carlosperezs@alumnos.uvigo.es

    #1

    Doubt with wx.CallAfter



    Hello together::

    I have programmed this fuction:

    def OnNewMovie(self , event):
    """ Local user receives a new movie event from a user"""

    #self.log.debug ( "Got OnNewMovie, " + `event`)
    if event.data[0] == self.pubId:
    fDep.write("New movie equal\n")
    fDep.flush()
    #self.log.debug ( "Returning, it's my movie")
    # This lets two users connect at the same time
    self.lockInitSe ssion.acquire()
    if self.vInitSessi on == False:
    self.vInitSessi on = True
    self.lockInitSe ssion.release()
    else:
    self.lockInitSe ssion.release()

    return


    #self.log.debug ( "Doing remote load event id = " + `event.data[0]` + ",
    myid=" + `self.pubId`)
    self.lockInitSe ssion.acquire()
    self.vInitSessi on = False
    self.lockInitSe ssion.release()

    self.sharedAppC lient.UpdateDat aCache()
    self.GetState()
    wx.CallAfter(se lf.sm.RemoteLoa dMovie)

    This function is a handler that is executed when a event occurs. At the end is
    wx.CallAfter call.
    Imagine that two events occur simultaneously. This function takes one event.
    After executing ax.CallAfter call would tke the second event. Then , my doubt
    would be, would be there 2 threads simultanously executing: one belongs to
    self.sm.RemoteL oadMovie and the another one belongs to the handler for the
    second event?

    Thank you. As you can see i do not know exactly how wx.CallAfter works.

    --oOo-----------------------------------------------------------------oOo--

    Servicio de acceso ó correo electrónico vía web da Universidade de Vigo
    Servicio de acceso al correo electrónico vía web de la Universidad de Vigo

    Servicios Informáticos [ http://si.uvigo.es ]
    Universidade de Vigo [ http://www.uvigo.es ]

    URL: https://correoweb.uvigo.es

  • Tim Roberts

    #2
    Re: Doubt with wx.CallAfter

    carlosperezs@al umnos.uvigo.es wrote:[color=blue]
    >
    >Hello together::
    >
    >I have programmed this fuction:
    >
    >def OnNewMovie(self , event):
    > """ Local user receives a new movie event from a user"""
    >
    > #self.log.debug ( "Got OnNewMovie, " + `event`)
    > if event.data[0] == self.pubId:
    > fDep.write("New movie equal\n")
    > fDep.flush()
    > #self.log.debug ( "Returning, it's my movie")
    > # This lets two users connect at the same time
    > self.lockInitSe ssion.acquire()
    > if self.vInitSessi on == False:
    > self.vInitSessi on = True
    > self.lockInitSe ssion.release()
    > else:
    > self.lockInitSe ssion.release()
    > return
    >
    > #self.log.debug ( "Doing remote load event id = " + `event.data[0]` + ",
    >myid=" + `self.pubId`)
    > self.lockInitSe ssion.acquire()
    > self.vInitSessi on = False
    > self.lockInitSe ssion.release()
    >
    > self.sharedAppC lient.UpdateDat aCache()
    > self.GetState()
    > wx.CallAfter(se lf.sm.RemoteLoa dMovie)
    >
    >This function is a handler that is executed when a event occurs. At the end is
    >wx.CallAfter call.
    >Imagine that two events occur simultaneously.[/color]

    Two events cannot occur simultaneously. It is impossible. There is only
    one message queue for your window. All messages will funnel through that
    one queue. There is one message loop for the thread that owns the window,
    which is pulling messages from the queue and dispatching them to message
    handlers. It cannot pull another message from the queue until you have
    finished processing this one and returned to the message loop.
    [color=blue]
    >This function takes one event.
    >After executing ax.CallAfter call would tke the second event. Then , my doubt
    >would be, would be there 2 threads simultanously executing: one belongs to
    >self.sm.Remote LoadMovie and the another one belongs to the handler for the
    >second event?[/color]

    No. wxCallAfter basically posts another message to the message queue,
    which will be handled after all the existing messages have been dispatched.
    Windows message handling is quite synchronous.
    --
    - Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

    Comment

    Working...