На питона 2,7Python, с которого начинается нить?
#!/usr/bin/env python
import time, threading, os
def f1(arg1):
for i in xrange(arg1):
time.sleep(1)
print "i is: ", i
print threading.enumerate()
if __name__ == '__main__':
t = threading.Thread(name="MyThread1", target=f1, args=(5,))
t.start()
t.join()
$ ./threadeg.py
i is: 0
[<_MainThread(MainThread, started 140502713374464)>, <Thread(MyThread1, started 140502683985664)>]
i is: 1
[<_MainThread(MainThread, started 140502713374464)>, <Thread(MyThread1, started 140502683985664)>]
i is: 2
[<_MainThread(MainThread, started 140502713374464)>, <Thread(MyThread1, started 140502683985664)>]
i is: 3
[<_MainThread(MainThread, started 140502713374464)>, <Thread(MyThread1, started 140502683985664)>]
i is: 4
[<_MainThread(MainThread, started 140502713374464)>, <Thread(MyThread1, started 140502683985664)>]
Вопрос:
Почему начали раз показывают, что основной поток начал после MyThread1? то есть MainThread_starttime - MyThread1_starttime> 0
Быстрый бесполезный ответ, потому что я нахожусь на своем телефоне, но прочитал источник для модуля потоков, и он должен стать ясным :-) – Iguananaut