Python in multi-threading, if write a call iamthreading inherited multi-threaded class, how to start it, is a problem.
What's the problem? It's not starting.
For I in Xrange (threads_num): t = iamthreading () threads.append (t) for I in Xrange (threads_num): Threads[i] . Start () for I in Xrange (threads_num): threads[i].join ()
But isn't it too ugly? After a long use, unbearable, too ugly!
So come a dashing
While 1: iamthreading (). Start ()
One go, however, this can not stop the program to run, can't stop, not satisfied.
So, I wrote:
threads = [Iamthreadingr () for I in Xrange (threads_num)] if [(J.setdaemon (True), J.start ())-j in threads] = = [ I.join () for I in Threads]: print ' All wars is civil wars,because all men is a . '
Take this to get rid of ugly for parallelism sentence, but see "= =" equal sign, will not just calculate a discovery on the right side, go to the next step?
See if Python will do this:
>>> from Queue import queue>>> q = Queue (0) >>> q.put (9) >>> Q.put (8) >>> Q.put (7) >>> Q.put (6) >>> if [1, 2, 3] = = [Q.get () for I in Xrange (3)]: ... Print "Hei hei" ...>>> q.get () 6>>>
It seems that Python will produce a complete list to compare.
Try again:
>>> from Queue import queue>>> q = Queue (0) >>> q.put (9) >>> Q.put (8) >>> Q.put (7) >>> Q.put (6) >>> if [] = = [Q.get () for I in Xrange (3)]: ... Print "Hei hei" ...>>> q.get () 6>>>
This is reassuring, it seems that the method is good.
Graceful start multithreading [Python]