child process

Ignacio Vazquez-Abrams ignacio at openservices.net
Mon Aug 27 03:51:32 EDT 2001


On Mon, 27 Aug 2001, Brian Lee wrote:

> Hi,
>
> I made a child process by fork function. When the mother
> process is killed, the child process is killed also.
>
> But I want child process not to be killed even the mother
> process is killed. How can I child process run independently?

Simple: Don't allow the parent to die before the child is done. The threading
module is good for this.

> Any examples code?

---
#! /usr/bin/python1.5

import sys
import os
import time
import threading

thread=None

def child():
  print 'Child started!'
  print 'Child delaying...'
  time.sleep(10)
  print 'Child done!'


print 'Parent started!'
thread=threading.Thread(None, child, 'child')
thread.start()
print 'Parent joining!'
thread.join()
print 'Parent done!'
sys.exit(0)
---

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>






More information about the Python-list mailing list