From 338c33a62bf42d4773c27b0b23047f4d7b68f86e Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 21 Dec 2020 11:16:51 -0800 Subject: [PATCH] forgot to remove debug prints, add comment about BoardImpl lock.. --- bitelab/__init__.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/bitelab/__init__.py b/bitelab/__init__.py index 80dfc31..4adf5af 100644 --- a/bitelab/__init__.py +++ b/bitelab/__init__.py @@ -234,11 +234,8 @@ class TimeOut(Attribute): @_tbprinter async def timeout_coro(self): - print('tc1') async with self._brd.lock: - print('tc2') await self._brd.release() - print('tc3') def timeout_callback(self): self._task = asyncio.create_task(self.timeout_coro()) @@ -276,6 +273,13 @@ class SerialConsole(DefROAttribute): raise RuntimeError('activate failed: %d' % ret) class BoardImpl: + ''' + This implements the interface for a board. The lock, inst.lock, + needs to be locked before most method calls. This is to ensure + that the board is in a stable state, such as the jail will not + be destroyed before the operation completes. + ''' + def __init__(self, name, brdclass, options): self.name = name self.brdclass = brdclass @@ -1641,7 +1645,6 @@ class TestAttrs(unittest.IsolatedAsyncioTestCase): # that the expiration is no longer there self.assertIsNone(to._exp) - print('z') # and the timeout passes evt = asyncio.Event() @@ -1649,33 +1652,26 @@ class TestAttrs(unittest.IsolatedAsyncioTestCase): loop.call_at(exp + epsilon, evt.set) await evt.wait() - print('a') # that when reserved/activated async with brd.lock: await brd.reserve() await brd.activate() - print('b') # but the board is locked for some reason await brd.lock.acquire() - print('c') # and the callback is called await asyncio.sleep(.02) - print('d') # that the task has been scheduled self.assertIsNotNone(to._task) - print('e') # that it can be deactivated await brd.deactivate() - print('f') # and when the board lock is released brd.lock.release() - print('g') # that the board was not released self.assertTrue(brd.reserved)