Skip to content

Commit c2b9e60

Browse files
committed
gateway_base: remove execmodel.{WorkerPool,PopenPiped}
`execmodel.WorkerPool` creates an unneeded dependency cycle. And it's not any better than the alternative really. `execmodel.PopenPiped` is a convenience that's not really needed at the abstraction layer, clearer to just inline it to the one place it's used.
1 parent 6c56e88 commit c2b9e60

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

execnet/gateway_base.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ def __getattr__(self, name):
117117
def fdopen(self, fd, mode, bufsize=1):
118118
return self._fdopen(fd, mode, bufsize)
119119

120-
def WorkerPool(self, hasprimary=False):
121-
return WorkerPool(self, hasprimary=hasprimary)
122-
123120
def Semaphore(self, size=None):
124121
if size is None:
125122
return EmptySemaphore()
@@ -134,10 +131,6 @@ def RLock(self):
134131
def Event(self):
135132
return self._event.Event()
136133

137-
def PopenPiped(self, args):
138-
PIPE = self.subprocess.PIPE
139-
return self.subprocess.Popen(args, stdout=PIPE, stdin=PIPE)
140-
141134
return ExecModel(backend)
142135

143136

@@ -909,7 +902,7 @@ def __init__(self, io, id, _startcount=2):
909902
# globals may be NONE at process-termination
910903
self.__trace = trace
911904
self._geterrortext = geterrortext
912-
self._receivepool = self.execmodel.WorkerPool()
905+
self._receivepool = WorkerPool(self.execmodel)
913906

914907
def _trace(self, *msg):
915908
self.__trace(self.id, *msg)
@@ -1011,7 +1004,7 @@ def trace(msg):
10111004
self._trace("[serve] " + msg)
10121005

10131006
hasprimary = self.execmodel.backend == "thread"
1014-
self._execpool = self.execmodel.WorkerPool(hasprimary=hasprimary)
1007+
self._execpool = WorkerPool(self.execmodel, hasprimary=hasprimary)
10151008
trace("spawning receiver thread")
10161009
self._initreceive()
10171010
try:

execnet/gateway_io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
class Popen2IOMaster(Popen2IO):
1919
def __init__(self, args, execmodel):
20-
self.popen = p = execmodel.PopenPiped(args)
20+
PIPE = execmodel.subprocess.PIPE
21+
self.popen = p = execmodel.subprocess.Popen(args, stdout=PIPE, stdin=PIPE)
2122
super().__init__(p.stdin, p.stdout, execmodel=execmodel)
2223

2324
def wait(self):

execnet/multi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from . import gateway_io
1313
from .gateway_base import get_execmodel
1414
from .gateway_base import trace
15+
from .gateway_base import WorkerPool
1516
from .xspec import XSpec
1617

1718
NO_ENDMARKER_WANTED = object()
@@ -292,7 +293,7 @@ def waitclose(self):
292293

293294

294295
def safe_terminate(execmodel, timeout, list_of_paired_functions):
295-
workerpool = execmodel.WorkerPool()
296+
workerpool = WorkerPool(execmodel)
296297

297298
def termkill(termfunc, killfunc):
298299
termreply = workerpool.spawn(termfunc)

0 commit comments

Comments
 (0)