thread question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rolf Wester

    thread question

    Hi,

    I have an application that starts a second thread, that receives
    messages via a socket-server and puts that messages into a queue. The
    main thread is polling that queue for new messages. My problem is that
    the main thread takes to much of the time polling the empty queue while
    the socket-server thread doesn't get enough time for receiving the
    messages. Is it possible to force the main threat to sleep for a certain
    amount of time or give the socket-server thread a higher priority?
    Thanks in advance.

    Kind regards

    Rolf Wester

  • Syver Enstad

    #2
    Re: thread question

    Rolf Wester <wester@ilt.fra unhofer.de> writes:
    [color=blue]
    > Hi,
    >
    > I have an application that starts a second thread, that receives
    > messages via a socket-server and puts that messages into a queue. The
    > main thread is polling that queue for new messages. My problem is that
    > the main thread takes to much of the time polling the empty queue
    > while the socket-server thread doesn't get enough time for receiving
    > the messages. Is it possible to force the main threat to sleep for a
    > certain
    > amount of time or give the socket-server thread a higher priority?
    > Thanks in advance.[/color]

    The good answer to your question:
    Use a Queue.Queue instance as your queue. The queue instance has
    methods that block if the queue is empty.

    The direct answer to your question:
    import time
    time.sleep(5) # sleeps 5 seconds

    Comment

    • Christoph Becker-Freyseng

      #3
      Re: thread question

      Hi,

      You can also use threading.Condi tion()
      This is useful for having some max. time and additionaly being able t
      start processing earlier again via cond.notify()

      Christoph Becker-Freyseng



      Rolf Wester wrote:[color=blue]
      > Hi,
      >
      > I have an application that starts a second thread, that receives
      > messages via a socket-server and puts that messages into a queue. The
      > main thread is polling that queue for new messages. My problem is that
      > the main thread takes to much of the time polling the empty queue while
      > the socket-server thread doesn't get enough time for receiving the
      > messages. Is it possible to force the main threat to sleep for a certain
      > amount of time or give the socket-server thread a higher priority?
      > Thanks in advance.
      >
      > Kind regards
      >
      > Rolf Wester
      >[/color]



      Comment

      Working...