Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11338

thread and process

From "守株待兔" <1248283536@qq.com>
Subject thread and process
Date 2011-08-13 17:09 +0800
Newsgroups comp.lang.python
Message-ID <mailman.2251.1313226603.1164.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

please see my code:
import os
import  threading
print  threading.currentThread()  
print "i am parent ",os.getpid()
ret  =  os.fork()
print  "i am here",os.getpid()
print  threading.currentThread()
if  ret  ==  0:
         print  threading.currentThread()
else:
        os.wait()
        print  threading.currentThread()
        
        
print "i am runing,who am i? ",os.getpid(),threading.currentThread()

the output is:
<_MainThread(MainThread, started -1216477504)>
i am parent  13495
i am here 13495
<_MainThread(MainThread, started -1216477504)>
i am here 13496
<_MainThread(MainThread, started -1216477504)>
<_MainThread(MainThread, started -1216477504)>
i am runing,who am i?  13496 <_MainThread(MainThread, started -1216477504)>
<_MainThread(MainThread, started -1216477504)>
i am runing,who am i?  13495 <_MainThread(MainThread, started -1216477504)>
it is so strange that  two  different  processes  use one  mainthread!!

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

thread and process "守株待兔" <1248283536@qq.com> - 2011-08-13 17:09 +0800
  Re: thread and process aspineux <aspineux@gmail.com> - 2011-08-13 03:01 -0700
  Re: thread and process Carl Banks <pavlovevidence@gmail.com> - 2011-08-13 03:52 -0700

csiph-web