Get or create the current DataContext. When a Dataset is created, the current DataContext will be sealed. Changes to `DataContext.get_current()` will not impact existing Datasets. Examples: .. testcode:: import ray context = ray
()
| 954 | |
| 955 | @staticmethod |
| 956 | def get_current() -> "DataContext": |
| 957 | """Get or create the current DataContext. |
| 958 | |
| 959 | When a Dataset is created, the current DataContext will be sealed. |
| 960 | Changes to `DataContext.get_current()` will not impact existing Datasets. |
| 961 | |
| 962 | Examples: |
| 963 | |
| 964 | .. testcode:: |
| 965 | import ray |
| 966 | |
| 967 | context = ray.data.DataContext.get_current() |
| 968 | |
| 969 | context.target_max_block_size = 100 * 1024 ** 2 |
| 970 | ds1 = ray.data.range(1) |
| 971 | context.target_max_block_size = 1 * 1024 ** 2 |
| 972 | ds2 = ray.data.range(1) |
| 973 | |
| 974 | # ds1's target_max_block_size will be 100MB |
| 975 | ds1.take_all() |
| 976 | # ds2's target_max_block_size will be 1MB |
| 977 | ds2.take_all() |
| 978 | |
| 979 | Developer notes: Avoid using `DataContext.get_current()` in data |
| 980 | internal components, use the DataContext object captured in the |
| 981 | Dataset and pass it around as arguments. |
| 982 | """ |
| 983 | |
| 984 | global _default_context |
| 985 | |
| 986 | with _context_lock: |
| 987 | if _default_context is None: |
| 988 | _default_context = DataContext() |
| 989 | |
| 990 | return _default_context |
| 991 | |
| 992 | @staticmethod |
| 993 | @contextlib.contextmanager |
no test coverage detected