MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_repr_lock

Method test_repr_lock

Lib/test/_test_multiprocessing.py:1397–1443  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1395 time.sleep(1.0)
1396
1397 def test_repr_lock(self):
1398 if self.TYPE != 'processes':
1399 self.skipTest('test not appropriate for {}'.format(self.TYPE))
1400
1401 lock = self.Lock()
1402 self.assertEqual(f'<Lock(owner=None)>', repr(lock))
1403
1404 lock.acquire()
1405 self.assertEqual(f'<Lock(owner=MainProcess)>', repr(lock))
1406 lock.release()
1407
1408 tname = 'T1'
1409 l = []
1410 t = threading.Thread(target=self._acquire,
1411 args=(lock, l),
1412 name=tname)
1413 t.start()
1414 time.sleep(0.1)
1415 self.assertEqual(f'<Lock(owner=MainProcess|{tname})>', l[0])
1416 lock.release()
1417
1418 t = threading.Thread(target=self._acquire,
1419 args=(lock,),
1420 name=tname)
1421 t.start()
1422 time.sleep(0.1)
1423 self.assertEqual('<Lock(owner=SomeOtherThread)>', repr(lock))
1424 lock.release()
1425
1426 pname = 'P1'
1427 l = multiprocessing.Manager().list()
1428 p = self.Process(target=self._acquire,
1429 args=(lock, l),
1430 name=pname)
1431 p.start()
1432 p.join()
1433 self.assertEqual(f'<Lock(owner={pname})>', l[0])
1434
1435 lock = self.Lock()
1436 event = self.Event()
1437 p = self.Process(target=self._acquire_event,
1438 args=(lock, event),
1439 name='P2')
1440 p.start()
1441 event.wait()
1442 self.assertEqual(f'<Lock(owner=SomeOtherProcess)>', repr(lock))
1443 p.terminate()
1444
1445 def test_lock(self):
1446 lock = self.Lock()

Callers

nothing calls this directly

Calls 15

acquireMethod · 0.95
releaseMethod · 0.95
startMethod · 0.95
waitMethod · 0.95
terminateMethod · 0.95
reprFunction · 0.85
skipTestMethod · 0.80
LockMethod · 0.80
ManagerMethod · 0.80
EventMethod · 0.80
formatMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected