Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default_ctx support for Config argument #351

Merged
merged 2 commits into from
Jun 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions tiledb/libtiledb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,39 @@ cdef Ctx _global_ctx = None
def _get_global_ctx():
return _global_ctx

def default_ctx():
"""Returns the default tiledb.Ctx object"""
def default_ctx(config = None):
"""
Returns, and optionally initializes, the default tiledb.Ctx object

For initialization, this function must be called before any other
tiledb functions. Initialization allows to pass a `Config` object
overriding defaults for process-global parameters such as the TBB
thread count.

:param config (default None): Config object or dictionary with config parameters.
:return: Ctx
"""
global _global_ctx
if _global_ctx is None:
_global_ctx = Ctx()
if _global_ctx is not None:
if config is not None:
raise TileDBError("Global context already initialized!")
else:
_global_ctx = Ctx(config)

return _global_ctx

def initialize_ctx(config = None):
"""
(deprecated) Please use `tiledb.default_ctx(config)`.

Initialize the TileDB-Py default Ctx. This function exists primarily to
allow configuration overrides for global per-process parameters, such as
the TBB thread count in particular.

:param config: Config object or dictionary with config parameters.
:return: None
"""
global _global_ctx
if _global_ctx is not None:
raise TileDBError("Global context already initialized!")
_global_ctx = Ctx(config)
return default_ctx(config)

###############################################################################
# MODULAR IMPORTS #
Expand Down