def testMonkeyPatch(self): pthreading.monkey_patch() import thread import threading self.assertEquals(thread.allocate_lock, pthreading.Lock) self.assertEquals(threading.Lock, pthreading.Lock) self.assertEquals(threading.RLock, pthreading.RLock) self.assertEquals(threading.Condition, pthreading.Condition)
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')
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')
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
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # import sys # When using Python 2, we must monkey patch threading module before importing # any other module. if sys.version_info[0] == 2: import pthreading pthreading.monkey_patch() import zombiereaper zombiereaper.registerSignalHandler() from vdsm import utils import testlib class FakeSanlock(object): """ Minimal test double exposing what the tests needs at this point. """ HOST_UNKNOWN = 1 HOST_FREE = 2 HOST_LIVE = 3
def test_monkey_patch_twice(self, monkeypatch): monkeypatch.delitem(sys.modules, "thread") monkeypatch.delitem(sys.modules, "threading") pthreading.monkey_patch() pthreading.monkey_patch() self.check_monkey_patch()
def test_monkey_patch_twice(self): pthreading.monkey_patch() pthreading.monkey_patch() self.check_monkey_patch()