MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / _model_with_slow_build

Function _model_with_slow_build

tests/test_models.py:1165–1185  ·  view source on GitHub ↗
(entered: threading.Event, release: threading.Event, builds: List[str])

Source from the content-addressed store, hash-verified

1163
1164
1165def _model_with_slow_build(entered: threading.Event, release: threading.Event, builds: List[str]) -> Any:
1166 from pydantic_core import core_schema
1167
1168 owner = os.getpid()
1169
1170 class Slow(str):
1171 @classmethod
1172 def __get_pydantic_core_schema__(cls, source: Any, handler: Any) -> Any:
1173 # A forked child must not touch these events: another thread may have held their locks at the fork.
1174 if os.getpid() == owner:
1175 builds.append(threading.current_thread().name)
1176 entered.set()
1177 release.wait(10)
1178 return core_schema.str_schema()
1179
1180 class Model(BaseModel):
1181 # scripts/test sets DEFER_PYDANTIC_BUILD=false, so defer this model's build explicitly
1182 model_config = {"defer_build": True}
1183 name: Slow
1184
1185 return Model
1186
1187
1188@pytest.mark.skipif(PYDANTIC_V1, reason="defer_build is only supported in pydantic v2")

Calls

no outgoing calls

Tested by

no test coverage detected