Threads

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

    #1

    Threads

    Hi all,

    In Python, Threads cannot be paused, i remember reading this somewhere,
    so is there a way around this ?

    TIA

  • Carl J. Van Arsdall

    #2
    Re: Threads

    placid wrote:[color=blue]
    > Hi all,
    >
    > In Python, Threads cannot be paused, i remember reading this somewhere,
    > so is there a way around this ?
    >[/color]

    When you say paused do you mean paused by an external source or paused
    by a call internal to the thread? There are plenty of synchronization
    constructs for making threads wait: Check out Events and Conditions

    -carl



    --

    Carl J. Van Arsdall
    cvanarsdall@mvi sta.com
    Build and Release
    MontaVista Software

    Comment

    • placid

      #3
      Re: Threads


      Carl J. Van Arsdall wrote:[color=blue]
      > placid wrote:[color=green]
      > > Hi all,
      > >
      > > In Python, Threads cannot be paused, i remember reading this somewhere,
      > > so is there a way around this ?
      > >[/color]
      >
      > When you say paused do you mean paused by an external source or paused
      > by a call internal to the thread? There are plenty of synchronization
      > constructs for making threads wait: Check out Events and Conditions[/color]

      I have a thread that has a job Queue, it continuosly polls this queue
      to see if there are any jobs for it, what i really wont to be able to
      do is, when the queue is empty, i want the thread to pause (or more
      technical, i want the thread to block) until the queue gets populated
      again. Is this possible ?

      [color=blue]
      >
      > -carl
      >
      >
      >
      > --
      >
      > Carl J. Van Arsdall
      > cvanarsdall@mvi sta.com
      > Build and Release
      > MontaVista Software[/color]

      Comment

      • David Reed

        #4
        Re: Threads


        On May 11, 2006, at 8:02 PM, placid wrote:
        [color=blue]
        >
        > Carl J. Van Arsdall wrote:[color=green]
        >> placid wrote:[color=darkred]
        >>> Hi all,
        >>>
        >>> In Python, Threads cannot be paused, i remember reading this
        >>> somewhere,
        >>> so is there a way around this ?
        >>>[/color]
        >>
        >> When you say paused do you mean paused by an external source or
        >> paused
        >> by a call internal to the thread? There are plenty of
        >> synchronization
        >> constructs for making threads wait: Check out Events and Conditions[/color]
        >
        > I have a thread that has a job Queue, it continuosly polls this queue
        > to see if there are any jobs for it, what i really wont to be able to
        > do is, when the queue is empty, i want the thread to pause (or more
        > technical, i want the thread to block) until the queue gets populated
        > again. Is this possible ?
        >
        >[/color]


        The previous poster answered your question - you want to use a
        condition variable.



        Dave

        Comment

        • placid

          #5
          Re: Threads


          David Reed wrote:[color=blue]
          > On May 11, 2006, at 8:02 PM, placid wrote:
          >[color=green]
          > >
          > > Carl J. Van Arsdall wrote:[color=darkred]
          > >> placid wrote:
          > >>> Hi all,
          > >>>
          > >>> In Python, Threads cannot be paused, i remember reading this
          > >>> somewhere,
          > >>> so is there a way around this ?
          > >>>
          > >>
          > >> When you say paused do you mean paused by an external source or
          > >> paused
          > >> by a call internal to the thread? There are plenty of
          > >> synchronization
          > >> constructs for making threads wait: Check out Events and Conditions[/color]
          > >
          > > I have a thread that has a job Queue, it continuosly polls this queue
          > > to see if there are any jobs for it, what i really wont to be able to
          > > do is, when the queue is empty, i want the thread to pause (or more
          > > technical, i want the thread to block) until the queue gets populated
          > > again. Is this possible ?
          > >
          > >[/color]
          >
          >
          > The previous poster answered your question - you want to use a
          > condition variable.
          >
          > http://docs.python.org/lib/condition-objects.html[/color]

          thanks, this is what i was after
          [color=blue]
          >
          > Dave[/color]

          Comment

          • Peter Otten

            #6
            Re: Threads

            placid wrote:
            [color=blue]
            > I have a thread that has a job Queue, it continuosly polls this queue
            > to see if there are any jobs for it, what i really wont to be able to
            > do is, when the queue is empty, i want the thread to pause (or more
            > technical, i want the thread to block) until the queue gets populated
            > again. Is this possible ?[/color]

            Isn't that the default behaviour of Queue.get()?

            Peter

            Comment

            • Alex Martelli

              #7
              Re: Threads

              Peter Otten <__peter__@web. de> wrote:
              [color=blue]
              > placid wrote:
              >[color=green]
              > > I have a thread that has a job Queue, it continuosly polls this queue
              > > to see if there are any jobs for it, what i really wont to be able to
              > > do is, when the queue is empty, i want the thread to pause (or more
              > > technical, i want the thread to block) until the queue gets populated
              > > again. Is this possible ?[/color]
              >
              > Isn't that the default behaviour of Queue.get()?[/color]

              Absolutely! placid, just call the get method of that Queue instance: if
              the queue is empty your thread DOES pause, or block, until there's some
              item put on the queue by another thread.


              Alex

              Comment

              • Edward Elliott

                #8
                Re: Threads

                Dennis Lee Bieber wrote:
                [color=blue]
                > On 11 May 2006 17:02:51 -0700, "placid" <Bulkan@gmail.c om> declaimed the
                > following in comp.lang.pytho n:[color=green]
                >> do is, when the queue is empty, i want the thread to pause (or more
                >> technical, i want the thread to block) until the queue gets populated
                >> again. Is this possible ?
                >>[/color]
                > Did you read the documentation for Queue methods?
                >
                > x = q.get(true) #blocks until data is available[/color]

                Like a good lawyer, Dennis knows the answer before he asks the question.

                --
                Edward Elliott
                UC Berkeley School of Law (Boalt Hall)
                complangpython at eddeye dot net

                Comment

                • placid

                  #9
                  Re: Threads


                  Dennis Lee Bieber wrote:[color=blue]
                  > On 11 May 2006 17:02:51 -0700, "placid" <Bulkan@gmail.c om> declaimed the
                  > following in comp.lang.pytho n:
                  >
                  >[color=green]
                  > > I have a thread that has a job Queue, it continuosly polls this queue
                  > > to see if there are any jobs for it, what i really wont to be able to
                  > > do is, when the queue is empty, i want the thread to pause (or more
                  > > technical, i want the thread to block) until the queue gets populated
                  > > again. Is this possible ?
                  > >[/color]
                  > Did you read the documentation for Queue methods?[/color]

                  there is no need to be patronizing about this dude, im just learning
                  Python in my spare time, as im a Intern Software Engineer
                  [color=blue]
                  >
                  > x = q.get(true) #blocks until data is available[/color]


                  this is even better, thanks dude
                  [color=blue]
                  > --
                  > Wulfraed Dennis Lee Bieber KD6MOG
                  > wlfraed@ix.netc om.com wulfraed@bestia ria.com
                  > HTTP://wlfraed.home.netcom.com/
                  > (Bestiaria Support Staff: web-asst@bestiaria. com)
                  > HTTP://www.bestiaria.com/[/color]

                  Comment

                  • Sybren Stuvel

                    #10
                    Re: Threads

                    placid enlightened us with:[color=blue][color=green]
                    >> Did you read the documentation for Queue methods?[/color]
                    >
                    > there is no need to be patronizing about this dude, im just learning
                    > Python in my spare time, as im a Intern Software Engineer[/color]

                    There is nothing patronizing about the question, it's merely an
                    enquiry to a possible fact. If you're going to be a techie, you should
                    learn stuff like that.

                    Sybren
                    --
                    The problem with the world is stupidity. Not saying there should be a
                    capital punishment for stupidity, but why don't we just take the
                    safety labels off of everything and let the problem solve itself?
                    Frank Zappa

                    Comment

                    • placid

                      #11
                      Re: Threads


                      Sybren Stuvel wrote:[color=blue]
                      > placid enlightened us with:[color=green][color=darkred]
                      > >> Did you read the documentation for Queue methods?[/color]
                      > >
                      > > there is no need to be patronizing about this dude, im just learning
                      > > Python in my spare time, as im a Intern Software Engineer[/color]
                      >
                      > There is nothing patronizing about the question, it's merely an
                      > enquiry to a possible fact. If you're going to be a techie, you should[/color]

                      true enough
                      [color=blue]
                      > learn stuff like that.[/color]

                      its always said that (in programming) that the easiest solution to a
                      problem is hard to find, well for me posting my question here was the
                      hardest, when the easier solution was for me to go look at the Python
                      documentation!
                      [color=blue]
                      >
                      > Sybren
                      > --
                      > The problem with the world is stupidity. Not saying there should be a
                      > capital punishment for stupidity, but why don't we just take the
                      > safety labels off of everything and let the problem solve itself?
                      > Frank Zappa[/color]

                      Comment

                      • Sybren Stuvel

                        #12
                        Re: Threads

                        placid enlightened us with:[color=blue]
                        > its always said that (in programming) that the easiest solution to a
                        > problem is hard to find[/color]

                        Yeah, that's true allright!

                        Sybren
                        --
                        The problem with the world is stupidity. Not saying there should be a
                        capital punishment for stupidity, but why don't we just take the
                        safety labels off of everything and let the problem solve itself?
                        Frank Zappa

                        Comment

                        • antred

                          #13
                          Re: Threads

                          Aww shoot, I never knew that!! LOL, I implemented my own worker thread
                          class using a mutex protected job list and a pair of connected sockets
                          for interprocess communication when I could just have used the darn
                          Queue module instead. Grrrrr .... hehe.

                          Comment

                          • Grant Edwards

                            #14
                            Re: Threads

                            On 2006-05-12, antred <NutJob@gmx.net > wrote:

                            Nerver knew what? Please quote for context.
                            [color=blue]
                            > Aww shoot, I never knew that!![/color]



                            get([block[, timeout]])

                            Remove and return an item from the queue. If optional args
                            block is true and timeout is None (the default), block if
                            necessary until an item is available. [...]

                            --
                            Grant Edwards grante Yow! VICARIOUSLY
                            at experience some reason
                            visi.com to LIVE!!

                            Comment

                            • Grant Edwards

                              #15
                              Re: Threads

                              On 2006-05-12, Sybren Stuvel <sybrenUSE@YOUR thirdtower.com. imagination> wrote:[color=blue]
                              > placid enlightened us with:[color=green][color=darkred]
                              >>> Did you read the documentation for Queue methods?[/color]
                              >>
                              >> there is no need to be patronizing about this dude, im just learning
                              >> Python in my spare time, as im a Intern Software Engineer[/color]
                              >
                              > There is nothing patronizing about the question, it's merely
                              > an enquiry to a possible fact. If you're going to be a techie,
                              > you should learn stuff like that.[/color]

                              It's also valuable information to the maintainers of the
                              documentation. If he _did_ read the documentation and still
                              didn't know that Queue.get() could block, then one might ask
                              how the documentation could be improved.

                              --
                              Grant Edwards grante Yow! Is this ANYWHERE,
                              at USA?
                              visi.com

                              Comment

                              Working...