Skip to content

Commit 3a678d9

Browse files
committed
Abstract Thread/Task wrapper for general use
1 parent a287c61 commit 3a678d9

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

test/asynchronous/utils_spec_runner.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,11 @@
6161
PARENT = object
6262

6363

64-
class SpecRunnerTask(PARENT):
65-
def __init__(self, name):
66-
super().__init__()
64+
class ConcurrentRunner(PARENT):
65+
def __init__(self, name, *args, **kwargs):
66+
if _IS_SYNC:
67+
super().__init__(*args, **kwargs)
6768
self.name = name
68-
self.exc = None
69-
self.daemon = True
70-
self.cond = _async_create_condition(_async_create_lock())
71-
self.ops = []
7269
self.stopped = False
7370
self.task = None
7471

@@ -84,6 +81,15 @@ async def join(self, timeout: float | None = 0): # type: ignore[override]
8481
def is_alive(self):
8582
return not self.stopped
8683

84+
85+
class SpecRunnerTask(ConcurrentRunner):
86+
def __init__(self, name):
87+
super().__init__(name)
88+
self.exc = None
89+
self.daemon = True
90+
self.cond = _async_create_condition(_async_create_lock())
91+
self.ops = []
92+
8793
async def schedule(self, work):
8894
self.ops.append(work)
8995
async with self.cond:

test/utils_spec_runner.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,11 @@
6161
PARENT = object
6262

6363

64-
class SpecRunnerThread(PARENT):
65-
def __init__(self, name):
66-
super().__init__()
64+
class ConcurrentRunner(PARENT):
65+
def __init__(self, name, *args, **kwargs):
66+
if _IS_SYNC:
67+
super().__init__(*args, **kwargs)
6768
self.name = name
68-
self.exc = None
69-
self.daemon = True
70-
self.cond = _create_condition(_create_lock())
71-
self.ops = []
7269
self.stopped = False
7370
self.task = None
7471

@@ -84,6 +81,15 @@ def join(self, timeout: float | None = 0): # type: ignore[override]
8481
def is_alive(self):
8582
return not self.stopped
8683

84+
85+
class SpecRunnerThread(ConcurrentRunner):
86+
def __init__(self, name):
87+
super().__init__(name)
88+
self.exc = None
89+
self.daemon = True
90+
self.cond = _create_condition(_create_lock())
91+
self.ops = []
92+
8793
def schedule(self, work):
8894
self.ops.append(work)
8995
with self.cond:

0 commit comments

Comments
 (0)