Get data from a Queue to a wxtextcontrol

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stygian
    New Member
    • May 2007
    • 6

    Get data from a Queue to a wxtextcontrol

    Hello, from linux I have created an interactive telnet session with a chess server.

    With a combination of the threading, pexpect and Queue modules I put all recieved data into a queue.

    The only way I can think of getting the data from the queue to a
    wxtextcontrol is to have a wx.timer (set to a short interval) keep inspecting the queue.

    This method seems to work OK, but I am wondering if there is a 'better' method than using a timer.

    If wx.timer is the only method, if I use an interval of 1 will the timer just run as fast as possible or should I try to find an exact value (eg 100) ?
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by stygian
    Hello, from linux I have created an interactive telnet session with a chess server.

    With a combination of the threading, pexpect and Queue modules I put all recieved data into a queue.

    The only way I can think of getting the data from the queue to a
    wxtextcontrol is to have a wx.timer (set to a short interval) keep inspecting the queue.

    This method seems to work OK, but I am wondering if there is a 'better' method than using a timer.

    If wx.timer is the only method, if I use an interval of 1 will the timer just run as fast as possible or should I try to find an exact value (eg 100) ?
    I like the idea of using a wxTimer to keep the display current with data that may be changing in the background. In fact, I use this technique often. I don't think that it's a good idea to run "as fast as possible", though. You only want to run fast enough (probably twice as fast as it takes for new data to arrive) to keep up with the changes in the data. I'd say that if you're entering the OnTimerN() handler and finding an empty queue more than 4 times for every time you find new data in the queue, you'll save processing overhead by cutting the value down (perhaps in half).

    Just my opinion, though.

    Comment

    • stygian
      New Member
      • May 2007
      • 6

      #3
      Originally posted by bartonc
      I like the idea of using a wxTimer to keep the display current with data that may be changing in the background. In fact, I use this technique often. I don't think that it's a good idea to run "as fast as possible", though. You only want to run fast enough (probably twice as fast as it takes for new data to arrive) to keep up with the changes in the data. I'd say that if you're entering the OnTimerN() handler and finding an empty queue more than 4 times for every time you find new data in the queue, you'll save processing overhead by cutting the value down (perhaps in half).

      Just my opinion, though.
      That's interesting, I hate the idea of wasting resources, BUT the data from the server is 'arratic' at best. Sometimes 20secs between lines then 50 lines arrive together.
      Thanks for the tips, I'll have to experiment a bit more.

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by stygian
        That's interesting, I hate the idea of wasting resources, BUT the data from the server is 'arratic' at best. Sometimes 20secs between lines then 50 lines arrive together.
        Thanks for the tips, I'll have to experiment a bit more.
        That make sense. I'm used to processes that require more regular servicing (like sampling analog data).

        Comment

        • stygian
          New Member
          • May 2007
          • 6

          #5
          Originally posted by bartonc
          That make sense. I'm used to processes that require more regular servicing (like sampling analog data).
          Brilliant! I followed your previous advise on counting the number of times timer tries to read an empty queue. After a bit of tweaking my code works so much better.
          Thanks

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by stygian
            Brilliant! I followed your previous advise on counting the number of times timer tries to read an empty queue. After a bit of tweaking my code works so much better.
            Thanks
            It makes me very happy that we can share and exchange our Python experience and knowledge this way. This forum is beginning to shape into the Python help forum of my dreams.

            Thank you so much for your participation.

            Comment

            Working...