Staging
v0.5.1
https://github.com/python/cpython
Revision 23cafd27cfd45f143c21a61319d230acc5ecf0ea authored by Benjamin Peterson on 04 April 2009, 15:38:19 UTC, committed by Benjamin Peterson on 04 April 2009, 15:38:19 UTC
........
  r70711 | r.david.murray | 2009-03-30 10:14:01 -0500 (Mon, 30 Mar 2009) | 2 lines

  Convert import try/except to use test_support.import_module().
........
  r70713 | ronald.oussoren | 2009-03-30 10:20:46 -0500 (Mon, 30 Mar 2009) | 2 lines

  This patch fixes issue 1254695 (wrong argument type conversion in Carbon.Qt)
........
  r70716 | r.david.murray | 2009-03-30 10:30:34 -0500 (Mon, 30 Mar 2009) | 2 lines

  Revert incorrect change.
........
  r70719 | ronald.oussoren | 2009-03-30 11:01:51 -0500 (Mon, 30 Mar 2009) | 2 lines

  Fix for issue 896199 (some Carbon modules aren't present in the documentation)
........
  r70747 | r.david.murray | 2009-03-30 15:04:06 -0500 (Mon, 30 Mar 2009) | 3 lines

  Remove references to test_socket_ssl which was deleted in trunk
  in r64392 and py3k in r59038.
........
  r70772 | barry.warsaw | 2009-03-30 17:42:17 -0500 (Mon, 30 Mar 2009) | 5 lines

  A fix for issue 1974, inspired by the patch from Andi Albrecht (aalbrecht),
  though with some changes by me.  This patch should not be back ported or
  forward ported.  It's a bit too risky for 2.6 and 3.x does things fairly
  differently.
........
  r70821 | jeremy.hylton | 2009-03-31 10:04:15 -0500 (Tue, 31 Mar 2009) | 2 lines

  Add check for PyDict_Update() error.
........
  r70830 | georg.brandl | 2009-03-31 11:11:45 -0500 (Tue, 31 Mar 2009) | 1 line

  #5529: backport new docs of import semantics written by Brett to 2.x.
........
  r70844 | raymond.hettinger | 2009-03-31 12:47:06 -0500 (Tue, 31 Mar 2009) | 1 line

  Per the language summit, the optional fastpath imports should use from-import-star.
........
  r70873 | josiah.carlson | 2009-03-31 14:32:34 -0500 (Tue, 31 Mar 2009) | 2 lines

  This resolves issue 1161031.  Tests pass.
........
  r70901 | georg.brandl | 2009-03-31 16:40:24 -0500 (Tue, 31 Mar 2009) | 2 lines

  Remove warning about pending Win9x support removal.
........
  r70902 | georg.brandl | 2009-03-31 16:43:03 -0500 (Tue, 31 Mar 2009) | 1 line

  #1675026: add a note about a strange Windows problem, and remove notes about AtheOS.
........
  r70904 | josiah.carlson | 2009-03-31 16:49:36 -0500 (Tue, 31 Mar 2009) | 3 lines

  Made handle_expt_event() be called last, so that we don't accidentally read
  after closing the socket.
........
  r70918 | raymond.hettinger | 2009-03-31 17:43:03 -0500 (Tue, 31 Mar 2009) | 1 line

  Improve examples for collections.deque()
........
  r70934 | josiah.carlson | 2009-03-31 20:28:11 -0500 (Tue, 31 Mar 2009) | 2 lines

  Fix for failing asyncore tests.
........
  r70969 | raymond.hettinger | 2009-04-01 13:50:56 -0500 (Wed, 01 Apr 2009) | 1 line

  Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
........
  r71026 | benjamin.peterson | 2009-04-01 21:52:46 -0500 (Wed, 01 Apr 2009) | 1 line

  fix error handling
........
  r71073 | raymond.hettinger | 2009-04-02 17:25:40 -0500 (Thu, 02 Apr 2009) | 4 lines

  Have namedtuple's field renamer assign names that
  are consistent with the corresponding tuple index.
........
  r71075 | raymond.hettinger | 2009-04-02 17:34:17 -0500 (Thu, 02 Apr 2009) | 1 line

  Update docs for namedtuple's renaming change.
........
  r71078 | raymond.hettinger | 2009-04-02 21:43:54 -0500 (Thu, 02 Apr 2009) | 4 lines

  Localize the function lookup in timeit.
........
1 parent 85b3098
Raw File
Tip revision: 23cafd27cfd45f143c21a61319d230acc5ecf0ea authored by Benjamin Peterson on 04 April 2009, 15:38:19 UTC
Blocked revisions 70711,70713,70716,70719,70747,70772,70821,70830,70844,70873,70901-70902,70904,70918,70934,70969,71026,71073,71075,71078 via svnmerge
Tip revision: 23cafd2
_dummy_thread.py
"""Drop-in replacement for the thread module.

Meant to be used as a brain-dead substitute so that threaded code does
not need to be rewritten for when the thread module is not present.

Suggested usage is::

    try:
        import _thread
    except ImportError:
        import _dummy_thread as _thread

"""
# Exports only things specified by thread documentation;
# skipping obsolete synonyms allocate(), start_new(), exit_thread().
__all__ = ['error', 'start_new_thread', 'exit', 'get_ident', 'allocate_lock',
           'interrupt_main', 'LockType']

import traceback as _traceback

class error(Exception):
    """Dummy implementation of _thread.error."""

    def __init__(self, *args):
        self.args = args

def start_new_thread(function, args, kwargs={}):
    """Dummy implementation of _thread.start_new_thread().

    Compatibility is maintained by making sure that ``args`` is a
    tuple and ``kwargs`` is a dictionary.  If an exception is raised
    and it is SystemExit (which can be done by _thread.exit()) it is
    caught and nothing is done; all other exceptions are printed out
    by using traceback.print_exc().

    If the executed function calls interrupt_main the KeyboardInterrupt will be
    raised when the function returns.

    """
    if type(args) != type(tuple()):
        raise TypeError("2nd arg must be a tuple")
    if type(kwargs) != type(dict()):
        raise TypeError("3rd arg must be a dict")
    global _main
    _main = False
    try:
        function(*args, **kwargs)
    except SystemExit:
        pass
    except:
        _traceback.print_exc()
    _main = True
    global _interrupt
    if _interrupt:
        _interrupt = False
        raise KeyboardInterrupt

def exit():
    """Dummy implementation of _thread.exit()."""
    raise SystemExit

def get_ident():
    """Dummy implementation of _thread.get_ident().

    Since this module should only be used when _threadmodule is not
    available, it is safe to assume that the current process is the
    only thread.  Thus a constant can be safely returned.
    """
    return -1

def allocate_lock():
    """Dummy implementation of _thread.allocate_lock()."""
    return LockType()

def stack_size(size=None):
    """Dummy implementation of _thread.stack_size()."""
    if size is not None:
        raise error("setting thread stack size not supported")
    return 0

class LockType(object):
    """Class implementing dummy implementation of _thread.LockType.

    Compatibility is maintained by maintaining self.locked_status
    which is a boolean that stores the state of the lock.  Pickling of
    the lock, though, should not be done since if the _thread module is
    then used with an unpickled ``lock()`` from here problems could
    occur from this class not having atomic methods.

    """

    def __init__(self):
        self.locked_status = False

    def acquire(self, waitflag=None):
        """Dummy implementation of acquire().

        For blocking calls, self.locked_status is automatically set to
        True and returned appropriately based on value of
        ``waitflag``.  If it is non-blocking, then the value is
        actually checked and not set if it is already acquired.  This
        is all done so that threading.Condition's assert statements
        aren't triggered and throw a little fit.

        """
        if waitflag is None or waitflag:
            self.locked_status = True
            return True
        else:
            if not self.locked_status:
                self.locked_status = True
                return True
            else:
                return False

    __enter__ = acquire

    def __exit__(self, typ, val, tb):
        self.release()

    def release(self):
        """Release the dummy lock."""
        # XXX Perhaps shouldn't actually bother to test?  Could lead
        #     to problems for complex, threaded code.
        if not self.locked_status:
            raise error
        self.locked_status = False
        return True

    def locked(self):
        return self.locked_status

# Used to signal that interrupt_main was called in a "thread"
_interrupt = False
# True when not executing in a "thread"
_main = True

def interrupt_main():
    """Set _interrupt flag to True to have start_new_thread raise
    KeyboardInterrupt upon exiting."""
    if _main:
        raise KeyboardInterrupt
    else:
        global _interrupt
        _interrupt = True
back to top