mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 03:00:23 -07:00
While the previous work on the foon class can't be quite recycled, it's still a nice abstraction.
This commit is contained in:
parent
73ca1a173c
commit
caab52aee2
2 changed files with 8 additions and 20 deletions
|
@ -63,7 +63,6 @@ PROCESS_LOCKFILE = tempfile.TemporaryFile()
|
||||||
|
|
||||||
from foon import Foon
|
from foon import Foon
|
||||||
|
|
||||||
FOON = Foon()
|
|
||||||
|
|
||||||
################################################
|
################################################
|
||||||
|
|
||||||
|
@ -1058,11 +1057,10 @@ class Runner(object):
|
||||||
|
|
||||||
# *****************************************************
|
# *****************************************************
|
||||||
|
|
||||||
def _parallel_exec(self, hosts):
|
def _parallel_exec(self, params):
|
||||||
''' handles mulitprocessing when more than 1 fork is required '''
|
''' handles mulitprocessing when more than 1 fork is required '''
|
||||||
|
|
||||||
FOON.set_size(self.forks)
|
return self.foon.map(_executor_hook, params)
|
||||||
return FOON.map(_executor_hook, hosts)
|
|
||||||
|
|
||||||
# *****************************************************
|
# *****************************************************
|
||||||
|
|
||||||
|
@ -1114,6 +1112,8 @@ class Runner(object):
|
||||||
if self.forks == 0 or self.forks > len(hosts):
|
if self.forks == 0 or self.forks > len(hosts):
|
||||||
self.forks = len(hosts)
|
self.forks = len(hosts)
|
||||||
|
|
||||||
|
self.foon = Foon(self.forks)
|
||||||
|
|
||||||
if p and getattr(p, 'BYPASS_HOST_LOOP', None):
|
if p and getattr(p, 'BYPASS_HOST_LOOP', None):
|
||||||
|
|
||||||
# Expose the current hostgroup to the bypassing plugins
|
# Expose the current hostgroup to the bypassing plugins
|
||||||
|
|
|
@ -99,30 +99,18 @@ class MyPool(mpool.Pool):
|
||||||
|
|
||||||
class Foon(object):
|
class Foon(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, size):
|
||||||
self.set_size(0)
|
self.pool = self._make_pool(size)
|
||||||
|
|
||||||
def make_pool(self, processes=None, initializer=None, initargs=()):
|
def _make_pool(self, processes=None, initializer=None, initargs=()):
|
||||||
'''
|
'''
|
||||||
Returns a process pool object
|
Returns a process pool object
|
||||||
'''
|
'''
|
||||||
return MyPool(processes, initializer, initargs)
|
return MyPool(processes, initializer, initargs)
|
||||||
|
|
||||||
def set_size(self, size):
|
|
||||||
|
|
||||||
global OLD_SIZE
|
|
||||||
global POOL
|
|
||||||
|
|
||||||
if size > OLD_SIZE or POOL is None:
|
|
||||||
OLD_SIZE = size
|
|
||||||
POOL = self.make_pool()
|
|
||||||
|
|
||||||
|
|
||||||
def map(self, function, data_list):
|
def map(self, function, data_list):
|
||||||
|
|
||||||
global POOL
|
|
||||||
try:
|
try:
|
||||||
return POOL.map(function, data_list)
|
return self.pool.map(function, data_list)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print "KEYBOARD INTERRUPT!"
|
print "KEYBOARD INTERRUPT!"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue