'Check fork() in main thread works while the main thread is doing an import'

def test_nested_import_lock_fork(self):

    def fork_with_import_lock(level):
        release = 0
        in_child = False
        try:
            try:
                for i in range(level):
                    imp.acquire_lock()
                    release += 1
                pid = os.fork()
                in_child = (not pid)
            finally:
                for i in range(release):
                    imp.release_lock()
        except RuntimeError:
            if in_child:
                if (verbose > 1):
                    print 'RuntimeError    in    child'
                os._exit(1)
            raise
        if in_child:
            os._exit(0)
        self.wait_impl(pid)
    for level in range(5):
        fork_with_import_lock(level)
