How to use test_one_thread method in autotest

Best Python code snippet using autotest_python

test_gil.py

Source:test_gil.py Github

copy

Full Screen

...23 raise NotImplementedError24class GILTests(test_rthread.AbstractGCTestClass):25 use_threads = True26 bigtest = False27 def test_one_thread(self, skew=+1):28 from rpython.rlib.debug import debug_print29 if self.bigtest:30 N = 10000031 skew *= 2500032 else:33 N = 10034 skew *= 2535 space = FakeSpace()36 class State:37 pass38 state = State()39 def runme(main=False):40 j = 041 for i in range(N + [-skew, skew][main]):42 state.datalen1 += 1 # try to crash if the GIL is not43 state.datalen2 += 1 # correctly acquired44 state.data.append((thread.get_ident(), i))45 state.datalen3 += 146 state.datalen4 += 147 assert state.datalen1 == len(state.data)48 assert state.datalen2 == len(state.data)49 assert state.datalen3 == len(state.data)50 assert state.datalen4 == len(state.data)51 debug_print(main, i, state.datalen4)52 gil.do_yield_thread()53 assert i == j54 j += 155 def bootstrap():56 try:57 runme()58 except Exception, e:59 assert 060 thread.gc_thread_die()61 def f():62 state.data = []63 state.datalen1 = 064 state.datalen2 = 065 state.datalen3 = 066 state.datalen4 = 067 state.threadlocals = gil.GILThreadLocals()68 state.threadlocals.setup_threads(space)69 thread.gc_thread_prepare()70 subident = thread.start_new_thread(bootstrap, ())71 mainident = thread.get_ident()72 runme(True)73 still_waiting = 300074 while len(state.data) < 2*N:75 debug_print(len(state.data))76 if not still_waiting:77 raise ValueError("time out")78 still_waiting -= 179 if not we_are_translated(): gil.before_external_call()80 time.sleep(0.01)81 if not we_are_translated(): gil.after_external_call()82 debug_print("leaving!")83 i1 = i2 = 084 for tid, i in state.data:85 if tid == mainident:86 assert i == i1; i1 += 187 elif tid == subident:88 assert i == i2; i2 += 189 else:90 assert 091 assert i1 == N + skew92 assert i2 == N - skew93 return len(state.data)94 fn = self.getcompiled(f, [])95 res = fn()96 assert res == 2*N97 def test_one_thread_rev(self):98 self.test_one_thread(skew=-1)99class TestRunDirectly(GILTests):100 def getcompiled(self, f, argtypes):101 return f102class TestUsingFramework(GILTests):103 gcpolicy = 'generation'...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful