SharedMemoryDataCatalog
kedro.io.SharedMemoryDataCatalog ¶
SharedMemoryDataCatalog(datasets=None, config_resolver=None, load_versions=None, save_version=None, validation_enabled=True)
Bases: DataCatalog
A specialized DataCatalog for managing datasets in a shared memory context.
The SharedMemoryDataCatalog extends the base DataCatalog to support multiprocessing
by ensuring that datasets are serializable and synchronized across threads or processes.
It provides additional functionality for managing shared memory datasets, such as setting
a multiprocessing manager and validating dataset compatibility with multiprocessing.
Attributes:
-
default_runtime_patterns(ClassVar) –A dictionary defining the default runtime pattern for datasets of type
kedro.io.SharedMemoryDataset.
Example:
from multiprocessing.managers import SyncManager
from kedro.io import MemoryDataset
from kedro.io.data_catalog import SharedMemoryDataCatalog
# Create a shared memory catalog
catalog = SharedMemoryDataCatalog(
datasets={"shared_data": MemoryDataset(data=[1, 2, 3])}
)
# Set a multiprocessing manager
manager = SyncManager()
manager.start()
catalog.set_manager_datasets(manager)
# Validate the catalog for multiprocessing compatibility
catalog.validate_catalog()
Source code in kedro/io/data_catalog.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
default_runtime_patterns
class-attribute
instance-attribute
¶
default_runtime_patterns = {'{default}': {'type': 'kedro.io.SharedMemoryDataset'}}
set_manager_datasets ¶
set_manager_datasets(manager)
Associate a multiprocessing manager with all shared memory datasets in the catalog.
This method iterates through all datasets in the catalog and sets the provided
multiprocessing manager for datasets of type SharedMemoryDataset. This ensures
that these datasets are properly synchronized across threads or processes.
Parameters:
-
manager(SyncManager) –A multiprocessing manager to be associated with shared memory datasets.
Example:
from multiprocessing.managers import SyncManager
from kedro.io.data_catalog import SharedMemoryDataCatalog
catalog = SharedMemoryDataCatalog(datasets={"shared_data": MemoryDataset(data=[1, 2, 3])})
manager = SyncManager()
manager.start()
catalog.set_manager_datasets(manager)
print(catalog)
# {'shared_data': kedro.io.memory_dataset.MemoryDataset(data='<list>')}
Source code in kedro/io/data_catalog.py
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 | |
validate_catalog ¶
validate_catalog()
Validate the catalog to ensure all datasets are serializable and compatible with multiprocessing.
This method checks that all datasets in the catalog are serializable and do not include non-proxied memory datasets as outputs. Non-serializable datasets or datasets that rely on single-process memory cannot be used in a multiprocessing context. If any such datasets are found, an exception is raised with details.
If a non-serializable dataset appears to be backed by remote/cloud storage
(detected via its _protocol attribute), a UserWarning is also issued for
that dataset suggesting ThreadRunner or SequentialRunner as an
alternative, since cloud-based filesystem clients (e.g. via fsspec)
commonly cannot be pickled.
Raises:
-
AttributeError–If any datasets are found to be non-serializable or incompatible with multiprocessing.
Example:
from kedro.io.data_catalog import SharedMemoryDataCatalog
catalog = SharedMemoryDataCatalog(datasets={"shared_data": MemoryDataset(data=[1, 2, 3])})
try:
catalog.validate_catalog()
except AttributeError as e:
print(f"Validation failed: {e}")
# No error
Source code in kedro/io/data_catalog.py
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 | |