Python
1import time, datetime, threading 2 3def test(): 4 time.sleep(5) 5 print('other', datetime.datetime.now()) 6 7thread_obj = threading.Thread(target=test) 8thread_obj.start() 9print('main', datetime.datetime.now())
上記コードを実行したとき、何故下記のようにmainの方が先にくるのでしょうか?
どのような順でコードは実行されているのでしょうか?
(django2.x) C:\Users...>python thread.py
main 2018-05-12 13:31:30.339849
other 2018-05-12 13:31:35.344389
7行目にて以下のようなコードがあるためここでtest関数が呼ばれ、"other"が先に表示されるのではないでしょうか?
thread_obj = threading.Thread(target=test)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。