コード例 #1
0
ファイル: test_gil.py プロジェクト: charred/pypy
 def test_one_thread(self, skew=+1):
     from rpython.rlib.debug import debug_print
     if self.bigtest:
         N = 100000
         skew *= 25000
     else:
         N = 100
         skew *= 25
     space = FakeSpace()
     class State:
         pass
     state = State()
     def runme(main=False):
         j = 0
         for i in range(N + [-skew, skew][main]):
             state.datalen1 += 1   # try to crash if the GIL is not
             state.datalen2 += 1   # correctly acquired
             state.data.append((thread.get_ident(), i))
             state.datalen3 += 1
             state.datalen4 += 1
             assert state.datalen1 == len(state.data)
             assert state.datalen2 == len(state.data)
             assert state.datalen3 == len(state.data)
             assert state.datalen4 == len(state.data)
             debug_print(main, i, state.datalen4)
             gil.do_yield_thread()
             assert i == j
             j += 1
     def bootstrap():
         try:
             runme()
         except Exception, e:
             assert 0
         thread.gc_thread_die()
コード例 #2
0
ファイル: os_thread.py プロジェクト: mozillazg/pypy
 def bootstrap():
     # Note that when this runs, we already hold the GIL.  This is ensured
     # by rffi's callback mecanism: we are a callback for the
     # c_thread_start() external function.
     rthread.gc_thread_start()
     space = bootstrapper.space
     w_callable = bootstrapper.w_callable
     args = bootstrapper.args
     bootstrapper.nbthreads += 1
     bootstrapper.release()
     # run!
     try:
         bootstrapper.run(space, w_callable, args)
         # done
     except Exception as e:
         # oups! last-level attempt to recover.
         try:
             STDERR = 2
             os.write(STDERR, "Thread exited with ")
             os.write(STDERR, str(e))
             os.write(STDERR, "\n")
         except OSError:
             pass
     bootstrapper.nbthreads -= 1
     rthread.gc_thread_die()
コード例 #3
0
ファイル: test_thread.py プロジェクト: wdv4758h/revdb
 def bootstrap():
     rthread.gc_thread_start()
     _sleep(1)
     revdb.stop_point()
     _sleep(2)
     revdb.stop_point()
     rthread.gc_thread_die()
コード例 #4
0
ファイル: test_thread.py プロジェクト: wdv4758h/revdb
 def bootstrap():
     rthread.gc_thread_start()
     _sleep(1)
     print "BB"
     _sleep(2)
     print "BBB"
     rthread.gc_thread_die()
コード例 #5
0
 def bootstrap():
     # Note that when this runs, we already hold the GIL.  This is ensured
     # by rffi's callback mecanism: we are a callback for the
     # c_thread_start() external function.
     rthread.gc_thread_start()
     space = bootstrapper.space
     w_callable = bootstrapper.w_callable
     args = bootstrapper.args
     bootstrapper.nbthreads += 1
     bootstrapper.release()
     # run!
     try:
         bootstrapper.run(space, w_callable, args)
         # done
     except Exception as e:
         # oups! last-level attempt to recover.
         try:
             STDERR = 2
             os.write(STDERR, "Thread exited with ")
             os.write(STDERR, str(e))
             os.write(STDERR, "\n")
         except OSError:
             pass
     bootstrapper.nbthreads -= 1
     rthread.gc_thread_die()
コード例 #6
0
ファイル: test_thread.py プロジェクト: wdv4758h/revdb
 def bootstrap():
     rthread.gc_thread_start()
     _sleep(1)
     ec = EC(4567)
     raw_thread_local.set(ec)
     print raw_thread_local.get().value
     assert raw_thread_local.get() is ec
     rthread.gc_thread_die()
コード例 #7
0
ファイル: pystate.py プロジェクト: charred/pypy
def PyThreadState_Clear(space, tstate):
    """Reset all information in a thread state object.  The global
    interpreter lock must be held."""
    Py_DecRef(space, tstate.c_dict)
    tstate.c_dict = lltype.nullptr(PyObject.TO)
    space.threadlocals.leave_thread(space)
    space.getexecutioncontext().cleanup_cpyext_state()
    rthread.gc_thread_die()
コード例 #8
0
def PyThreadState_Clear(space, tstate):
    """Reset all information in a thread state object.  The global
    interpreter lock must be held."""
    if not space.config.translation.thread:
        raise NoThreads
    Py_DecRef(space, tstate.c_dict)
    tstate.c_dict = lltype.nullptr(PyObject.TO)
    space.threadlocals.leave_thread(space)
    space.getexecutioncontext().cleanup_cpyext_state()
    rthread.gc_thread_die()
コード例 #9
0
ファイル: test_standalone.py プロジェクト: juokaz/pypy
 def bootstrap():
     rthread.gc_thread_start()
     childpid = run_in_thread()
     gc.collect()  # collect both in the child and in the parent
     gc.collect()
     gc.collect()
     if childpid == 0:
         os.write(state.write_end, 'c')  # "I did not die!" from child
     else:
         os.write(state.write_end, 'p')  # "I did not die!" from parent
     rthread.gc_thread_die()
コード例 #10
0
ファイル: test_standalone.py プロジェクト: bukzor/pypy
 def bootstrap():
     rthread.gc_thread_start()
     childpid = run_in_thread()
     gc.collect()        # collect both in the child and in the parent
     gc.collect()
     gc.collect()
     if childpid == 0:
         os.write(state.write_end, 'c')   # "I did not die!" from child
     else:
         os.write(state.write_end, 'p')   # "I did not die!" from parent
     rthread.gc_thread_die()
コード例 #11
0
ファイル: os_thread.py プロジェクト: sota/pypy-old
class Bootstrapper(object):
    "A global container used to pass information to newly starting threads."

    # Passing a closure argument to rthread.start_new_thread() would be
    # theoretically nicer, but comes with messy memory management issues.
    # This is much more straightforward.

    nbthreads = 0

    # The following lock is held whenever the fields
    # 'bootstrapper.w_callable' and 'bootstrapper.args' are in use.
    lock = None
    args = None
    w_callable = None

    @staticmethod
    def setup(space):
        if bootstrapper.lock is None:
            try:
                bootstrapper.lock = rthread.allocate_lock()
            except rthread.error:
                raise wrap_thread_error(space, "can't allocate bootstrap lock")

    @staticmethod
    def reinit():
        bootstrapper.lock = None
        bootstrapper.nbthreads = 0
        bootstrapper.w_callable = None
        bootstrapper.args = None

    def _cleanup_(self):
        self.reinit()

    def bootstrap():
        # Note that when this runs, we already hold the GIL.  This is ensured
        # by rffi's callback mecanism: we are a callback for the
        # c_thread_start() external function.
        rthread.gc_thread_start()
        space = bootstrapper.space
        w_callable = bootstrapper.w_callable
        args = bootstrapper.args
        bootstrapper.nbthreads += 1
        bootstrapper.release()
        # run!
        try:
            bootstrapper.run(space, w_callable, args)
            # done
        except Exception, e:
            # oups! last-level attempt to recover.
            try:
                STDERR = 2
                os.write(STDERR, "Thread exited with ")
                os.write(STDERR, str(e))
                os.write(STDERR, "\n")
            except OSError:
                pass
        bootstrapper.nbthreads -= 1
        rthread.gc_thread_die()
コード例 #12
0
    def test_one_thread(self, skew=+1):
        from rpython.rlib.debug import debug_print
        if self.bigtest:
            N = 100000
            skew *= 25000
        else:
            N = 100
            skew *= 25
        space = FakeSpace()

        class State:
            pass

        state = State()

        def runme(main=False):
            j = 0
            for i in range(N + [-skew, skew][main]):
                state.datalen1 += 1  # try to crash if the GIL is not
                state.datalen2 += 1  # correctly acquired
                state.data.append((thread.get_ident(), i))
                state.datalen3 += 1
                state.datalen4 += 1
                assert state.datalen1 == len(state.data)
                assert state.datalen2 == len(state.data)
                assert state.datalen3 == len(state.data)
                assert state.datalen4 == len(state.data)
                debug_print(main, i, state.datalen4)
                rgil.yield_thread()
                assert i == j
                j += 1

        def bootstrap():
            try:
                runme()
            except Exception, e:
                assert 0
            thread.gc_thread_die()
コード例 #13
0
ファイル: test_gil.py プロジェクト: Mu-L/pypy
 def bootstrap():
     try:
         runme()
     except Exception as e:
         assert 0
     thread.gc_thread_die()
コード例 #14
0
ファイル: test_standalone.py プロジェクト: juokaz/pypy
 def bootstrap():
     rthread.gc_thread_start()
     check_errno(42)
     state.xlist.append(Cons(123, Cons(456, None)))
     gc.collect()
     rthread.gc_thread_die()
コード例 #15
0
ファイル: threads.py プロジェクト: zen3d/pixie
def bootstrap():
    rthread.gc_thread_start()
    fn = bootstrapper.fn()
    bootstrapper.release()
    safe_invoke(fn, [])
    rthread.gc_thread_die()
コード例 #16
0
ファイル: test_gil.py プロジェクト: mozillazg/pypy
 def bootstrap():
     try:
         runme()
     except Exception as e:
         assert 0
     thread.gc_thread_die()
コード例 #17
0
ファイル: test_standalone.py プロジェクト: bukzor/pypy
 def bootstrap():
     rthread.gc_thread_start()
     check_errno(42)
     state.xlist.append(Cons(123, Cons(456, None)))
     gc.collect()
     rthread.gc_thread_die()
コード例 #18
0
ファイル: threads.py プロジェクト: johnwalker/pixie
def bootstrap():
    rthread.gc_thread_start()
    fn = bootstrapper.fn()
    bootstrapper.release()
    fn.invoke([])
    rthread.gc_thread_die()