Author lesha
Recipients Giovanni.Bajo, avian, bobbyi, gregory.p.smith, jcea, lesha, neologix, nirai, pitrou, sbt, sdaoden, vinay.sajip, vstinner
Date 2012-06-01.00:25:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1338510302.26.0.284042780947.issue6721@psf.upfronthosting.co.za>
In-reply-to
Content
> I think forkall() on Solaris acts like that, but the normal fork() 
> function does not.  Only the thread which performs fork() will survive 
> in the child process.

Sorry, brain fail. A slightly more contrived failure case is this:

subprocess.Popen(
  ..., 
  preexec_fn=lambda: conn.doWork()
)

Everything else is the same.

Another failure case is:

  class MySQLConn:
    ... doWork as before ...

    def __del__(self):
      self.doWork()

Followed by:

  def thread3(conn):
    while True:
      subprocess.call(['nonexistent_program']) 
      time.sleep(0.1)

The destructor will fire in the child and corrupt the parent's data.

An analogous example is:

  conn = MySQLConn()
  start_thread1(conn)
  start_thread2(conn):
  while True:
    if os.fork() == 0:  # child
      raise Exception('doom')  # triggers destructor

Basically, it is really really dangerous to release locks that protect any resources that are not copied by fork (i.e. network resources, files, DB connections, etc, etc).
History
Date User Action Args
2012-06-01 00:25:02leshasetrecipients: + lesha, gregory.p.smith, vinay.sajip, jcea, pitrou, vstinner, nirai, bobbyi, neologix, Giovanni.Bajo, sdaoden, sbt, avian
2012-06-01 00:25:02leshasetmessageid: <1338510302.26.0.284042780947.issue6721@psf.upfronthosting.co.za>
2012-06-01 00:25:01leshalinkissue6721 messages
2012-06-01 00:25:01leshacreate