how to drop all thread ??

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

    #1

    how to drop all thread ??

    if class A(
    use threading,threa d module
    ) to produce 100 thread,how to drop its (100 thread) when its running


  • Diez B. Roggisch

    #2
    Re: how to drop all thread ??

    Leon wrote:
    [color=blue]
    > if class A(
    > use threading,threa d module
    > ) to produce 100 thread,how to drop its (100 thread) when its running[/color]

    By exiting. There is no other way to stop a thread by force. Of course you
    can write a run()-method like this:


    def run(self):
    while self.running_co ndition:
    # do something
    pass

    If that running-condition is queried often enough, you can stop the thread
    by setting it to false.

    --
    Regards,

    Diez B. Roggisch

    Comment

    • Peter Hansen

      #3
      Re: how to drop all thread ??

      Diez B. Roggisch wrote:[color=blue]
      > Leon wrote:
      >
      >[color=green]
      >>if class A(
      >>use threading,threa d module
      >>) to produce 100 thread,how to drop its (100 thread) when its running[/color]
      >
      >
      > By exiting. There is no other way to stop a thread by force.[/color]

      Note that even trying to exit won't work, if the threads are not
      marked as "daemon" threads... Only by calling .setDaemon(True ) on
      the threads before they are started will you be able to terminate
      them all just by exiting.

      -Peter

      Comment

      • Andrew Koenig

        #4
        Re: how to drop all thread ??

        This reply is off topic but I couldn't resist:

        The best way to get rid of thread is to adopt a kitten.

        In fact, one of my cats is named Snobol because she is such a good string
        manipulator.


        Comment

        • Michel Claveau - abstraction méta-galactique non t

          #5
          Re: how to drop all thread ??

          Hi !

          The best method, it is the suicide (of the threads).




          Comment

          • Chris S.

            #6
            Re: how to drop all thread ??

            Leon wrote:[color=blue]
            > if class A(
            > use threading,threa d module
            > ) to produce 100 thread,how to drop its (100 thread) when its running[/color]

            As Roggisch suggests, the cleanest way is if the thread kills itself
            once signaled by an exit condition. However, there is a non-orthodox way
            of pseudo-forcibly killing threads by catching the kill signal in a
            traceback. This method is summed up in Connelly Barnes's informal
            KThread module:


            Note it won't work in all cases, as it can't kill a thread that's made a
            blocking system call. However, it may come in useful.

            Comment

            Working...