Skip to content

Commit

Permalink
Merge pull request #989 from dimitri-yatsenko/key_populate
Browse files Browse the repository at this point in the history
Key populate
  • Loading branch information
ethho authored Sep 12, 2024
2 parents b9d8488 + b85c959 commit e14544d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions datajoint/autopopulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def _initialize_populate(table, jobs, populate_kwargs):
"""
Initialize the process for mulitprocessing.
Initialize the process for multiprocessing.
Saves the unpickled copy of the table to the current process and reconnects.
"""
process = mp.current_process()
Expand Down Expand Up @@ -153,6 +153,7 @@ def _jobs_to_do(self, restrictions):
def populate(
self,
*restrictions,
keys=None,
suppress_errors=False,
return_exception_objects=False,
reserve_jobs=False,
Expand All @@ -169,6 +170,8 @@ def populate(
:param restrictions: a list of restrictions each restrict
(table.key_source - target.proj())
:param keys: The list of keys (dicts) to send to self.make().
If None (default), then use self.key_source to query they keys.
:param suppress_errors: if True, do not terminate execution.
:param return_exception_objects: return error objects instead of just error messages
:param reserve_jobs: if True, reserve jobs to populate in asynchronous fashion
Expand Down Expand Up @@ -206,7 +209,10 @@ def handler(signum, frame):

old_handler = signal.signal(signal.SIGTERM, handler)

keys = (self._jobs_to_do(restrictions) - self.target).fetch("KEY", limit=limit)
if keys is None:
keys = (self._jobs_to_do(restrictions) - self.target).fetch(
"KEY", limit=limit
)

# exclude "error", "ignore" or "reserved" jobs
if reserve_jobs:
Expand Down Expand Up @@ -295,6 +301,7 @@ def _populate1(
:return: (key, error) when suppress_errors=True,
True if successfully invoke one `make()` call, otherwise False
"""
# use the legacy `_make_tuples` callback.
make = self._make_tuples if hasattr(self, "_make_tuples") else self.make

if jobs is not None and not jobs.reserve(
Expand Down
2 changes: 2 additions & 0 deletions datajoint/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ def cascade(table):
logger.warn("Nothing to delete.")
if transaction:
self.connection.cancel_transaction()
elif not transaction:
logger.info("Delete completed")
else:
if not safemode or user_choice("Commit deletes?", default="no") == "yes":
if transaction:
Expand Down

0 comments on commit e14544d

Please sign in to comment.