Help with Threading

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

    #1

    Help with Threading

    Hi

    I am fairly new to Python threading and my needs are simple(!)

    I want to establish a number of threads each of which work on the same
    computationally intensive problem in different ways.

    I am using the thread module rather than the threading module.

    My problem is I can't see how (when one thread completes) to ensure that the
    other threads terminate immediately.

    Appreciate some simple advice

    Phil


  • Dennis Lee Bieber

    #2
    Re: Help with Threading

    On Mon, 24 Jan 2005 05:15:07 GMT, "Philip Smith"
    <as006d4848@blu eyonder.co.uk> declaimed the following in
    comp.lang.pytho n:
    [color=blue]
    >
    > My problem is I can't see how (when one thread completes) to ensure that the
    > other threads terminate immediately.
    >[/color]
    I presume your threads contain some sort of loop structure at
    some stage...

    Insert a non-blocking test on some shared condition variable,
    and have the thread terminate /itself/ when the condition is set. The
    condition would need to be set, by your code, by whichever thread should
    complete first, on its own.

    May not even need a condition/event/lock -- a globally shared
    variable might be sufficient.

    --[color=blue]
    > =============== =============== =============== =============== == <
    > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
    > wulfraed@dm.net | Bestiaria Support Staff <
    > =============== =============== =============== =============== == <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

    Comment

    • Pierre Barbier de Reuille

      #3
      Re: Help with Threading

      Philip Smith a écrit :[color=blue]
      > Hi
      >
      > I am fairly new to Python threading and my needs are simple(!)
      >
      > I want to establish a number of threads each of which work on the same
      > computationally intensive problem in different ways.
      >
      > I am using the thread module rather than the threading module.
      >
      > My problem is I can't see how (when one thread completes) to ensure that the
      > other threads terminate immediately.
      >
      > Appreciate some simple advice
      >
      > Phil
      >
      >[/color]

      With Python's threads, you have to handle this kindd a feature yourself.
      For example, you can create a single object containing a boolean set to
      False by default. When one of your algorithm finishes, the boolean is
      set to True. All your algorithm should regularly test this boolean and
      exit if it is True ! Note that the boolean has to be inside another
      object because Boolean types is not mutable. Now, if you really want to
      be able to "kill" your threads, you will need another thread interface.
      For example, Qt threads allows that ... and WxPython offers you some
      functions to do exactly what I described.

      Pierre

      Comment

      • wittempj@hotmail.com

        #4
        Re: Help with Threading

        I use threading.Threa d as outlined in this recipe:


        Comment

        • Philip Smith

          #5
          Re: Help with Threading


          <wittempj@hotma il.com> wrote in message
          news:1106569451 .677064.86620@f 14g2000cwb.goog legroups.com...[color=blue]
          >I use threading.Threa d as outlined in this recipe:
          > http://aspn.activestate.com/ASPN/Coo...n/Recipe/65448
          >Thanks[/color]


          Comment

          Working...