~ubuntu-branches/ubuntu/oneiric/python2.5/oneiric

« back to all changes in this revision

Viewing changes to Lib/threading.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-12-21 08:57:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081221085749-bijjr25h8na5jdsu
Tags: 2.5.3-0ubuntu1
* New upstream version.
* Regenerate the included documentation.
* Add an option --install-layout=deb, which is ignored for 2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
766
766
    from _threading_local import local
767
767
 
768
768
 
 
769
def _after_fork():
 
770
    # This function is called by Python/ceval.c:PyEval_ReInitThreads which
 
771
    # is called from PyOS_AfterFork.  Here we cleanup threading module state
 
772
    # that should not exist after a fork.
 
773
 
 
774
    # Reset _active_limbo_lock, in case we forked while the lock was held
 
775
    # by another (non-forked) thread.  http://bugs.python.org/issue874900
 
776
    global _active_limbo_lock
 
777
    _active_limbo_lock = _allocate_lock()
 
778
 
 
779
    # fork() only copied the current thread; clear references to others.
 
780
    new_active = {}
 
781
    current = currentThread()
 
782
    _active_limbo_lock.acquire()
 
783
    try:
 
784
        for thread in _active.itervalues():
 
785
            if thread is current:
 
786
                # There is only one active thread. We reset the ident to
 
787
                # its new value since it can have changed.
 
788
                ident = _get_ident()
 
789
                thread._Thread__ident = ident
 
790
                new_active[ident] = thread
 
791
            else:
 
792
                # All the others are already stopped.
 
793
                # We don't call _Thread__stop() because it tries to acquire
 
794
                # thread._Thread__block which could also have been held while
 
795
                # we forked.
 
796
                thread._Thread__stopped = True
 
797
 
 
798
        _limbo.clear()
 
799
        _active.clear()
 
800
        _active.update(new_active)
 
801
        assert len(_active) == 1
 
802
    finally:
 
803
        _active_limbo_lock.release()
 
804
 
 
805
 
769
806
# Self-test code
770
807
 
771
808
def _test():