Do thread die?
Maurice LING
mauriceling at acm.org
Thu Sep 22 04:52:45 EDT 2005
Frithiof Andreas Jensen wrote:
> "Maurice LING" <mauriceling at acm.org> wrote in message
> news:dgh54e$e8c$1 at domitilla.aioe.org...
>
>
>>I do have another dumb question which is OT here. Say aFunc method
>>instantiates a SOAP server that serves forever, will it prevent bFunc
>>from running as a separate thread?
>
>
> If the SOAP server thread never sleeps or block, it will effectively stop
> everything else in your program by eating all the CPU time available. If it
> does some IO and other OS functions, probably not because it is likely to
> block on those - I do not know SOAPpy in detail, but it being a socket-based
> server it should end up in a select loop somewhere. i.e. block when no work
> is available. which is what you want.
>
>
>>For example,
>>
>>class myClass4:
>> def repeat(self, s): return s+s
>> def aFunc(self, a):
>> import SOAPpy
>> serv = SOAPpy.SOAPServer((a[0], a[1]))
>> serv.registerFunction(repeat)
>> serv.serve_forever()
>> def bFunc(self, b): pass
>> def runAll(self, a, b):
>> threading.Thread(target=self.aFunc, args = (a)).start()
>> threading.Thread(target=self.bFunc, args = (b)).start()
>>
>>if __name__=='__main__': myClass4().runAll(['localhost', 8000], 'hi')
>>
>>Will the 2nd thread (bFunc) ever run since the 1st thread is running
>>forever? Intuitively, I think that both threads will run but I just want
>>to be doubly sure, because some of my program logic depends on the 2nd
>>thread running while the 1st thread acts as a SOAP server or something.
>
>
> Both should run independently, sharing the CPU-time available for your
> application. Remember "main" is a thread too, so you will want "main" to
> hang around while your threads are running and you will want "main" to block
> on something also, thread.join(), time.sleep(), command line parser e.t.c.
> whatever is natural.
>
>
Somehow I cannot reconcile your replies because I am essentially asking
the same thing and expanding on the original question with an example of
what I am trying to do, but the replies seems contradictory. Do you mind
to explain a bit more?
thanks
Maurice
More information about the Python-list
mailing list