thds.mops 3.9.20250730010431__py3-none-any.whl → 3.9.20250730172122__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of thds.mops might be problematic. Click here for more details.

@@ -1,6 +1,7 @@
1
1
  from ._acquire import acquire # noqa: F401
2
2
  from .maintain import ( # noqa: F401
3
3
  CannotMaintainLock,
4
+ LockWasStolenError,
4
5
  launch_daemon_lock_maintainer,
5
6
  maintain_to_release,
6
7
  remote_lock_maintain,
@@ -101,7 +101,12 @@ def acquire( # noqa: C901
101
101
 
102
102
  start = _funcs.utc_now()
103
103
 
104
- my_writer_id = humenc.encode(uuid4().bytes)
104
+ my_writer_id = humenc.encode(uuid4().bytes, num_bytes=2)
105
+ # we do not expect there to be many writers, so we make the humenc part of the writer
106
+ # id relatively short so it doesn't 'look' like other uses of humenc. Making the rest
107
+ # of the string identical to the base64 encoding (by choosing a multiple of 3) is not
108
+ # useful to us because we are only using this as a big UUID, not as a hash of an
109
+ # actual input.
105
110
 
106
111
  lockfile_writer = LockfileWriter(
107
112
  my_writer_id,
@@ -52,9 +52,30 @@ class _ResultExcWithMetadataChannel:
52
52
  )
53
53
 
54
54
  def return_value(self, r: T) -> None:
55
+ result_uri = self.fs.join(self.call_id, results.RESULT)
56
+ if self.fs.exists(result_uri):
57
+ logger.warning("Not overwriting existing result at %s prior to serialization", result_uri)
58
+ self._write_metadata_only("lost-race")
59
+ return
60
+
61
+ # when we pickle the return value, we also end up potentially uploading
62
+ # various Sources and Paths and other special-cased things inside the result.
55
63
  return_value_bytes = _pickle.gimme_bytes(self.dumper, r)
64
+ if self.fs.exists(result_uri):
65
+ logger.warning("Not overwriting existing result at %s after serialization", result_uri)
66
+ self._write_metadata_only("lost-race-after-serialization")
67
+ return
68
+
69
+ # BUG: there remains a race condition between fs.exists and putbytes.
70
+ # multiple callers could get a False from fs.exists and then proceed to write.
71
+ # the biggest issue here is for functions that are not truly pure, because
72
+ # they will be writing different results, and theoretically different callers
73
+ # could end up seeing the different results.
74
+ #
75
+ # In the future, if a Blob Store provided a put_unless_exists method, we could use
76
+ # that to avoid the race condition.
56
77
  self.fs.putbytes(
57
- self.fs.join(self.call_id, results.RESULT),
78
+ result_uri,
58
79
  self._metadata_header + return_value_bytes,
59
80
  type_hint="application/mops-return-value",
60
81
  )
@@ -92,6 +113,8 @@ def run_pickled_invocation(memo_uri: str, *metadata_args: str) -> None:
92
113
 
93
114
  # any recursively-called functions that use metadata will retain the original invoker.
94
115
 
116
+ failure_to_lock = None
117
+ stop_lock: ty.Callable = lambda: None # noqa: E731
95
118
  try:
96
119
  stop_lock = lock.launch_daemon_lock_maintainer(
97
120
  lock.remote_lock_maintain(
@@ -100,7 +123,9 @@ def run_pickled_invocation(memo_uri: str, *metadata_args: str) -> None:
100
123
  )
101
124
  except lock.CannotMaintainLock as e:
102
125
  logger.info(f"Cannot maintain lock: {e}. Continuing without the lock.")
103
- stop_lock = lambda: None # noqa: E731
126
+ except lock.LockWasStolenError as e:
127
+ logger.error(f"Lock was stolen: {e}. Exiting without running the function.")
128
+ failure_to_lock = e
104
129
 
105
130
  def _extract_invocation_unique_key(memo_uri: str) -> ty.Tuple[str, str]:
106
131
  parts = fs.split(memo_uri)
@@ -124,6 +149,14 @@ def run_pickled_invocation(memo_uri: str, *metadata_args: str) -> None:
124
149
  def do_work_return_result() -> object:
125
150
  # ONLY failures in this code should transmit an EXCEPTION
126
151
  # back to the orchestrator side.
152
+
153
+ # if the lock was stolen, we should write an exception
154
+ # so that the orchestrator knows that it failed.
155
+ # in theory, it could resume waiting for a result, though
156
+ # currently it does not do this.
157
+ if failure_to_lock:
158
+ raise failure_to_lock
159
+
127
160
  with unwrap_use_runner(func):
128
161
  return func(*args, **kwargs)
129
162
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: thds.mops
3
- Version: 3.9.20250730010431
3
+ Version: 3.9.20250730172122
4
4
  Summary: ML Ops tools for Trilliant Health
5
5
  Author-email: Trilliant Health <info@trillianthealth.com>
6
6
  Project-URL: Repository, https://github.com/TrilliantHealth/ds-monorepo
@@ -66,8 +66,8 @@ thds/mops/pure/core/entry/__init__.py,sha256=kiDcsj16CwjRSexOZW-4h4b4tDCYIS_eLS5
66
66
  thds/mops/pure/core/entry/main.py,sha256=b1F5lFDK_hnpvW3bqzt5MWDcpKvCXZpWdEHI8zroC4k,2061
67
67
  thds/mops/pure/core/entry/route_result.py,sha256=2LcS9M2mYtu56kso0YcMEZbR1mbTWZm0hFlbE2yaf4k,2741
68
68
  thds/mops/pure/core/entry/runner_registry.py,sha256=aPDCML7gM_zP6NfPnqx0_Q1oRHzgdaCa_XzYc5VIw7U,601
69
- thds/mops/pure/core/lock/__init__.py,sha256=Fq5Fa9DGFcADFxfyFckSl1mYX7p8DAemjMKH9PMpb-s,240
70
- thds/mops/pure/core/lock/_acquire.py,sha256=O__mQCUQy0mx-JGNgQjbaSPbfCOXkaiJealYt2Av7Cg,9079
69
+ thds/mops/pure/core/lock/__init__.py,sha256=MVwbqK-tQX-Y20lhmofLHFoyEgkQGsaKa9a9JgCP4jc,264
70
+ thds/mops/pure/core/lock/_acquire.py,sha256=lVxHzDA30VB95Cfb4Fl2m0eatdLXCDv6rOCnERiyMNw,9468
71
71
  thds/mops/pure/core/lock/_funcs.py,sha256=j4g8yVWnrAMPDKqLlq8nTnccM1KHSJ3g71L1iWNbV2Q,969
72
72
  thds/mops/pure/core/lock/cli.py,sha256=uidtmgHB2y5LDkj7SQTncy_cNe1EfIseuiJPV9kcxBU,2488
73
73
  thds/mops/pure/core/lock/maintain.py,sha256=5IUQFAU96p46nNt6SMwTAlB2e0HGHJj8n7kqeRxb26M,5767
@@ -89,7 +89,7 @@ thds/mops/pure/pickling/_pickle.py,sha256=YB8xbqDiwdk8ccnVZ2_4kQn98V2JSrFqw2E3J-
89
89
  thds/mops/pure/pickling/memoize_only.py,sha256=oI5CMy6IEJc46Gb_BGWNUuAe3fysS7HxRSTajN0WssI,837
90
90
  thds/mops/pure/pickling/mprunner.py,sha256=vabdHIVteddkU5ncOq73wWC7-naChW_3_vvAQArvjqU,8814
91
91
  thds/mops/pure/pickling/pickles.py,sha256=CSlnjLssE0Ad8YzqyaKqWCSNyW5LiMFKiXO6hWAZmvU,5097
92
- thds/mops/pure/pickling/remote.py,sha256=l4bIDc7jg7923IFKBeJE3oJYCN4OeT5tmtAg1eS_k7c,6011
92
+ thds/mops/pure/pickling/remote.py,sha256=i2fD9WMuk3rqNxqnQWvkSw9lW6eXVdQ1laxXQWEB3hQ,7665
93
93
  thds/mops/pure/pickling/sha256_b64.py,sha256=HL0cPixHPZYuZDVDBscxsnI-3a2amWEfw-LseOX-PyY,2916
94
94
  thds/mops/pure/runner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
95
95
  thds/mops/pure/runner/get_results.py,sha256=1K6qf_Vg2YfUPfUuu103WyYsfS3e_ju6W7Z_PV01-pU,4053
@@ -109,8 +109,8 @@ thds/mops/pure/tools/summarize/cli.py,sha256=7kDtn24ok8oBO3jFjlMmOK3jnZYpMoE_5Y8
109
109
  thds/mops/pure/tools/summarize/run_summary.py,sha256=w45qiQr7elrHDiK9Hgs85gtU3gwLuXa447ih1Y23BBY,5776
110
110
  thds/mops/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
111
111
  thds/mops/testing/deferred_imports.py,sha256=f0ezCgQAtzTqW1yAOb0OWgsB9ZrlztLB894LtpWDaVw,3780
112
- thds_mops-3.9.20250730010431.dist-info/METADATA,sha256=SDHHsq-QNwEmuB66uQ50V_Iehj3fgcblyjOxxuglv4I,2225
113
- thds_mops-3.9.20250730010431.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
114
- thds_mops-3.9.20250730010431.dist-info/entry_points.txt,sha256=qKvCAaB80syXfxVR3xx6x9J0YJdaQWkIbVSw-NwFgMw,322
115
- thds_mops-3.9.20250730010431.dist-info/top_level.txt,sha256=LTZaE5SkWJwv9bwOlMbIhiS-JWQEEIcjVYnJrt-CriY,5
116
- thds_mops-3.9.20250730010431.dist-info/RECORD,,
112
+ thds_mops-3.9.20250730172122.dist-info/METADATA,sha256=DEv6JovXRJRIU7BlhFCiR0eQqH8nv2oBtq1P_dyOHvs,2225
113
+ thds_mops-3.9.20250730172122.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
114
+ thds_mops-3.9.20250730172122.dist-info/entry_points.txt,sha256=qKvCAaB80syXfxVR3xx6x9J0YJdaQWkIbVSw-NwFgMw,322
115
+ thds_mops-3.9.20250730172122.dist-info/top_level.txt,sha256=LTZaE5SkWJwv9bwOlMbIhiS-JWQEEIcjVYnJrt-CriY,5
116
+ thds_mops-3.9.20250730172122.dist-info/RECORD,,