Exemplo n.º 1
0
def test_monkeypatch_patch(monkeypatch):
    monkeypatch.delitem(sys.modules, "threading")
    monkeypatch.setattr(cthreading, "_patched", False)
    cthreading.monkeypatch()
    import thread
    import threading
    assert thread.allocate_lock is cthreading.Lock
    assert threading._allocate_lock is cthreading.Lock
    assert threading.Lock is cthreading.Lock
    assert threading.RLock is cthreading.RLock
    assert threading.Condition is cthreading.Condition
Exemplo n.º 2
0
def main(args):
    options, args = parse_args(args)

    if options.monkeypatch:
        if options.monkeypatch == "cthreading":
            import cthreading
            cthreading.monkeypatch()
        elif options.monkeypatch == "pthreading":
            import pthreading
            pthreading.monkey_patch()
        else:
            raise ValueError("Usupported monkeypatch %r" % options.monkeypatch)

    try:
        import Queue as queue
        _range = xrange
    except ImportError:
        import queue
        _range = range

    import threading

    if options.profile:
        import yappi
        yappi.set_clock_type('cpu')
        yappi.start(builtins=True, profile_threads=True)

    leftmost = queue.Queue()
    left = leftmost
    for i in _range(options.whispers):
        right = queue.Queue()
        t = threading.Thread(target=whisper, args=(left, right))
        t.daemon = True
        t.start()
        left = right

    for i in _range(options.jobs):
        right.put(1)

    for i in _range(options.jobs):
        n = leftmost.get()
        assert n == options.whispers + 1

    if options.profile:
        yappi.stop()
        stats = yappi.get_func_stats()
        stats.save(options.profile, 'pstat')
Exemplo n.º 3
0
def run(func, options):
    if options.monkeypatch:
        if options.monkeypatch == "cthreading":
            import cthreading
            cthreading.monkeypatch()
        elif options.monkeypatch == "pthreading":
            import pthreading
            pthreading.monkey_patch()
        else:
            raise ValueError("Usupported monkeypatch %r" % options.monkeypatch)

    if options.profile:
        import yappi
        yappi.set_clock_type('cpu')
        yappi.start(builtins=True, profile_threads=True)

    func(options)

    if options.profile:
        yappi.stop()
        stats = yappi.get_func_stats()
        stats.save(options.profile, 'pstat')
Exemplo n.º 4
0
def main(args):
    options, args = parse_args(args)

    if options.monkeypatch:
        if options.monkeypatch == "cthreading":
            import cthreading
            cthreading.monkeypatch()
        elif options.monkeypatch == "pthreading":
            import pthreading
            pthreading.monkey_patch()
        else:
            raise ValueError("Usupported monkeypatch %r" % options.monkeypatch)

    try:
        import Queue as queue
        _range = xrange
    except ImportError:
        import queue
        _range = range

    import threading

    src = queue.Queue()
    dst = queue.Queue()

    for i in _range(options.workers):
        t = threading.Thread(target=worker, args=(src, dst))
        t.daemon = True
        t.start()

    for i in _range(options.rounds):
        for j in _range(options.jobs):
            src.put(1)
        for j in _range(options.jobs):
            n = dst.get()
            assert n == 2
Exemplo n.º 5
0
def test_monkeypatch_twice(monkeypatch):
    monkeypatch.delitem(sys.modules, "threading")
    monkeypatch.delitem(sys.modules, "thread")
    monkeypatch.setattr(cthreading, "_patched", False)
    cthreading.monkeypatch()
    pytest.raises(RuntimeError, cthreading.monkeypatch)
Exemplo n.º 6
0
def test_monkeypatch_twice(monkeypatch):
    monkeypatch.delitem(sys.modules, "threading")
    monkeypatch.setattr(cthreading, "_patched", False)
    cthreading.monkeypatch()
    pytest.raises(RuntimeError, cthreading.monkeypatch)
Exemplo n.º 7
0
# Copyright 2015 Nir Soffer <*****@*****.**>
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v2 or (at your option) any later version.

import cthreading
cthreading.monkeypatch()

# Requires python-test package, not installed by default
from test import regrtest
regrtest.main()
Exemplo n.º 8
0
# Copyright 2015 Nir Soffer <*****@*****.**>
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v2 or (at your option) any later version.

import cthreading

cthreading.monkeypatch()

# Requires python-test package, not installed by default
from test import regrtest

regrtest.main()