Skip to content

Commit 0079a7e

Browse files
minor cleanup in autopopulate
1 parent b52a130 commit 0079a7e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

datajoint/autopopulate.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
# --- helper functions for multiprocessing --
1919

20-
def _initializer(table, jobs, populate_kwargs):
20+
def _initialize_populate(table, jobs, populate_kwargs):
2121
"""
22-
Process initializer for mulitprocessing.
22+
Initialize the process for mulitprocessing.
2323
Saves the unpickled copy of the table to the current process and reconnects.
2424
"""
2525
process = mp.current_process()
@@ -159,9 +159,9 @@ def handler(signum, frame):
159159

160160
logger.info('Found %d keys to populate' % len(keys))
161161

162-
if max_calls is not None:
163-
keys = keys[:max_calls]
162+
keys = keys[:max_calls]
164163
nkeys = len(keys)
164+
165165
if processes > 1:
166166
processes = min(processes, nkeys, mp.cpu_count())
167167

@@ -179,7 +179,7 @@ def handler(signum, frame):
179179
# spawn multiple processes
180180
self.connection.close() # disconnect parent process from MySQL server
181181
del self.connection._conn.ctx # SSLContext is not pickleable
182-
with mp.Pool(processes, _initializer, (self, populate_kwargs)) as pool:
182+
with mp.Pool(processes, _initialize_populate, (self, populate_kwargs)) as pool:
183183
if display_progress:
184184
with tqdm(desc="Processes: ", total=nkeys) as pbar:
185185
for error in pool.imap(_call_populate1, keys, chunksize=1):
@@ -201,12 +201,12 @@ def handler(signum, frame):
201201

202202
def _populate1(self, key, jobs, suppress_errors, return_exception_objects):
203203
"""
204-
populates table for one key, calling self.make inside a transaction
204+
populates table for one source key, calling self.make inside a transaction.
205205
:param jobs: the jobs table or None if not reserve_jobs
206206
:param key: dict specifying job to populate
207207
:param suppress_errors: bool if errors should be suppressed and returned
208208
:param return_exception_objects: if True, errors must be returned as objects
209-
:return: key and error when suppress_errors=True, otherwise None
209+
:return: (key, error) when suppress_errors=True, otherwise None
210210
"""
211211
make = self._make_tuples if hasattr(self, '_make_tuples') else self.make
212212

@@ -248,8 +248,8 @@ def _populate1(self, key, jobs, suppress_errors, return_exception_objects):
248248

249249
def progress(self, *restrictions, display=True):
250250
"""
251-
report progress of populating the table
252-
:return: remaining, total -- tuples to be populated
251+
Report the progress of populating the table.
252+
:return: (remaining, total) -- numbers of tuples to be populated
253253
"""
254254
todo = self._jobs_to_do(restrictions)
255255
total = len(todo)

0 commit comments

Comments
 (0)