Skip to content

Commit 7239588

Browse files
mgr/vol: reuse code for spawning threads
Signed-off-by: Rishabh Dave <[email protected]>
1 parent dcd399e commit 7239588

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/pybind/mgr/volumes/fs/async_job.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,17 @@ def __init__(self, volume_client, name_pfx, nr_concurrent_jobs):
137137

138138
self.threads = []
139139
for i in range(self.nr_concurrent_jobs):
140-
self.threads.append(JobThread(self, volume_client, name="{0}.{1}".format(self.name_pfx, i)))
141-
self.threads[-1].start()
140+
self.spawn_new_thread(i)
142141
self.start()
143142

143+
def spawn_new_thread(self, suffix):
144+
t_name = f'{self.name_pfx}.{time.time()}.{suffix}'
145+
log.debug(f'spawning new thread with name {t_name}')
146+
t = JobThread(self, self.vc, name=t_name)
147+
t.start()
148+
149+
self.threads.append(t)
150+
144151
def set_wakeup_timeout(self):
145152
with self.lock:
146153
# not made configurable on purpose
@@ -165,8 +172,7 @@ def run(self):
165172
# Increase concurrency: create more threads.
166173
log.debug("creating new threads to job increase")
167174
for i in range(c, self.nr_concurrent_jobs):
168-
self.threads.append(JobThread(self, self.vc, name="{0}.{1}.{2}".format(self.name_pfx, time.time(), i)))
169-
self.threads[-1].start()
175+
self.spawn_new_thread(i)
170176
self.cv.wait(timeout=self.wakeup_timeout)
171177

172178
def shutdown(self):

0 commit comments

Comments
 (0)