Skip to content

Commit b7f7b02

Browse files
enable specifying keys to populate
1 parent 6fbed92 commit b7f7b02

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

datajoint/autopopulate.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
def _initialize_populate(table, jobs, populate_kwargs):
2121
"""
22-
Initialize the process for mulitprocessing.
22+
Initialize the process for multiprocessing.
2323
Saves the unpickled copy of the table to the current process and reconnects.
2424
"""
2525
process = mp.current_process()
@@ -126,14 +126,17 @@ def _jobs_to_do(self, restrictions):
126126
pass
127127
return (todo & AndList(restrictions)).proj()
128128

129-
def populate(self, *restrictions, suppress_errors=False, return_exception_objects=False,
129+
def populate(self, *restrictions, keys=None, suppress_errors=False,
130+
return_exception_objects=False,
130131
reserve_jobs=False, order="original", limit=None, max_calls=None,
131132
display_progress=False, processes=1):
132133
"""
133134
table.populate() calls table.make(key) for every primary key in self.key_source
134135
for which there is not already a tuple in table.
135136
:param restrictions: a list of restrictions each restrict
136137
(table.key_source - target.proj())
138+
:param keys: The list of dicts to populate. When None (default),
139+
uses self.key_source to query keys to populate.
137140
:param suppress_errors: if True, do not terminate execution.
138141
:param return_exception_objects: return error objects instead of just error messages
139142
:param reserve_jobs: if True, reserve jobs to populate in asynchronous fashion
@@ -159,7 +162,8 @@ def handler(signum, frame):
159162
raise SystemExit('SIGTERM received')
160163
old_handler = signal.signal(signal.SIGTERM, handler)
161164

162-
keys = (self._jobs_to_do(restrictions) - self.target).fetch("KEY", limit=limit)
165+
keys = keys if keys is not None else \
166+
(self._jobs_to_do(restrictions) - self.target).fetch("KEY", limit=limit)
163167
if order == "reverse":
164168
keys.reverse()
165169
elif order == "random":
@@ -216,6 +220,7 @@ def _populate1(self, key, jobs, suppress_errors, return_exception_objects):
216220
:param return_exception_objects: if True, errors must be returned as objects
217221
:return: (key, error) when suppress_errors=True, otherwise None
218222
"""
223+
# use the legacy `_make_tuples` callback.
219224
make = self._make_tuples if hasattr(self, '_make_tuples') else self.make
220225

221226
if jobs is None or jobs.reserve(self.target.table_name, self._job_key(key)):

0 commit comments

Comments
 (0)