• Kirill Smelkov's avatar
    bigfile/py: Stop caring about sys.exc_{type,value,traceback} variables · 3804cc39
    Kirill Smelkov authored
    Before py3k python stores exception information not only in thread-local state
    but also globally in sys.exc_* variables (wrt sys.exc_info()) for
    "backward compatibility". However using them is not thread-safe as the
    following example demonstrates:
    ---- 8< ----
    from threading import Thread
    import sys
    def T1():
        print 'T1'
        while 1:
            exc_type = sys.exc_type
            if exc_type is not None:
                print 'AAA: %r' % exc_type
    def f(): g()
    def g(): h()
    def h(): 1/0
    def T2():
        print 'T2'
        while 1:
    t1, t2 = Thread(target=T1), Thread(target=T2)
    t1.start(); t2.start()
    ---- 8< ----
    ---- 8< ----
    kirr@deco:~/tmp/trashme/t$ ./excthreads.py
    AAA: <type 'exceptions.ZeroDivisionError'>
    AAA: <type 'exceptions.ZeroDivisionError'>
    AAA: <type 'exceptions.ZeroDivisionError'>
    AAA: <type 'exceptions.ZeroDivisionError'>
    AAA: <type 'exceptions.ZeroDivisionError'>
    AAA: <type 'exceptions.ZeroDivisionError'>
    ---- 8< ----
    Because of the above nothing modern (I've explicitly checked at least CPython
    itself and Zope) uses this variables - wherever needed per-thread exception
    state is retrieved with sys.exc_info().
    So on wendelin.core side it is thus thankless job to try to preserve sys.exc_*
    vars state because on a busy server they are literally changing all the -
    arbitrary from the point of view of particular thread - time while its python
    code runs.
Last commit
Last update
tests Loading commit data...
__init__.py Loading commit data...
_bigfile.c Loading commit data...
file_file.py Loading commit data...
file_zodb.py Loading commit data...
pagefault.c Loading commit data...
pagemap.c Loading commit data...
ram.c Loading commit data...
ram_hugetlbfs.c Loading commit data...
ram_shmfs.c Loading commit data...
virtmem.c Loading commit data...