tdfs4ds.utils.td_context¶
tdfs4ds.utils.td_context
¶
teradataml's current context: is one open, close it with a time limit, forget it.
teradataml changed where it keeps the connection. Up to 20.0.0.10 it is a module
global, teradataml.context.context.td_connection. From 20.0.0.12 the context is
an object, _global_context_instance (top of _context_stack), and the module
global stays None. Code that only read the global saw no connection at all on
20.0.0.12 (0.3.6.2's keep-alive never pinged, and its bounded close returned at
once) while tdml.remove_context() still ran its garbage collector over the
dead connection and blocked forever. Both layouts are read here, once.
tdml.remove_context() sends statements (query band reset, DROP VIEW of its
temporary objects) before closing. Over a connection the network dropped while
idle, the driver waits for an answer that never comes, so a close must be bounded.
DEAD_CONTEXT_MARKERS
module-attribute
¶
DEAD_CONTEXT_MARKERS = ("'nonetype' object has no attribute 'cursor'", 'is not a valid connection pool handle', 'current teradata vantage connection context is empty', 'tdml_2054')
context_swap
¶
wait_for_context
¶
Wait while a reconnect is swapping the context. True when a context is open.
_bounded
¶
Run fn in a daemon thread. Returns (finished, result_or_exception).
abandon_context
¶
Forget the current teradataml connection without sending anything over it.
close_context_bounded
¶
Close the teradataml context, giving up after timeout seconds.
Returns 'none' (nothing open), 'closed', 'failed' (the close raised;
the context is cleared anyway) or 'abandoned' (it did not return in time:
the context is cleared and the stuck call is left in its daemon thread).
_protected_records
¶
The pool records behind teradataml's own connection(s): never closed by a sweep.
harden_pool
¶
Make the teradataml engine's pool close only connections of dead threads.
Idempotent and fail-open; returns True when the pool is (now) hardened. Called after
every create_context the package makes; harmless on an engine with another pool.
is_dead_context_error
¶
True when exc says teradataml's connection is gone (the statement did not run).
context_state
¶
('open' | 'dead' | 'none', detail) without sending a statement.
dead = teradataml holds a connection object whose driver connection was closed;
none = no context at all.
was_open
¶
True once this process has had an open context (a dead one is only meaningful then).
probe_context
¶
SELECT 1 through teradataml, bounded. (ok, detail); never raises.
repair_context
¶
Reconnect teradataml's context once, whoever asks. True when a context is open after.
Threads that fail on the same dead connection all land here: the first reconnects, the
others find the generation moved and return at once. Logged at WARNING with reason
whatever DISPLAY_LOGS says.
retry_if_dead_context
¶
Run fn; when it fails because the context is dead, repair it and run it once more.
install_dead_context_retry
¶
Wrap the teradataml entry points every read goes through (once).
create_context.execute_sql (tdml.execute_sql), _global_function_executor (the
module-level calls), UtilFuncs._execute_query
(DataFrame reads) and _execute_ddl_statement: a call that fails with a dead-context
error repairs the context and runs once more. The statement never ran, so a write is
never repeated. Used by the admin app; harmless elsewhere.