Skip to content

Commit 749d703

Browse files
fixup! NO-SNOW: Add core library import
1 parent 009ca84 commit 749d703

File tree

5 files changed

+80
-13
lines changed

5 files changed

+80
-13
lines changed

src/snowflake/connector/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from functools import wraps
77

8-
from ._utils import core_loader
8+
from ._utils import _core_loader
99

1010
apilevel = "2.0"
1111
threadsafety = 2
@@ -47,17 +47,17 @@
4747
from .log_configuration import EasyLoggingConfigPython
4848
from .version import VERSION
4949

50-
logging.getLogger(__name__).addHandler(NullHandler())
51-
setup_external_libraries()
52-
5350
# Load the core library - failures are captured in core_loader and don't prevent module loading
5451
try:
55-
core_loader.load()
52+
_core_loader.load()
5653
except Exception:
5754
# Silently continue if core loading fails - the error is already captured in core_loader
5855
# This ensures the connector module loads even if the minicore library is unavailable
5956
pass
6057

58+
logging.getLogger(__name__).addHandler(NullHandler())
59+
setup_external_libraries()
60+
6161

6262
@wraps(SnowflakeConnection.__init__)
6363
def Connect(**kwargs) -> SnowflakeConnection:

src/snowflake/connector/_utils.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import importlib
55
import string
66
import sys
7+
import threading
78
from enum import Enum
89
from inspect import stack
910
from random import choice
@@ -112,7 +113,7 @@ def _get_core_path():
112113
if sys.platform.startswith("win"):
113114
lib_name = "libsf_mini_core.dll"
114115
elif sys.platform.startswith("darwin"):
115-
lib_name = "libsf_mini_core.dyldib"
116+
lib_name = "libsf_mini_core.dylib"
116117
else:
117118
lib_name = "libsf_mini_core.so"
118119

@@ -134,20 +135,32 @@ def _load_minicore(path: str) -> ctypes.CDLL:
134135
core = ctypes.CDLL(str(lib_path))
135136
return core
136137

137-
def load(self) -> None:
138+
def _load(self) -> None:
138139
try:
139140
path = self._get_core_path()
140141
core = self._load_minicore(path)
141142
self._register_functions(core)
142143
self._version = core.sf_core_full_version()
144+
self._error = None
143145
except Exception as err:
144146
self._error = err
145147

148+
def load(self):
149+
"""Spawn a separate thread to load the minicore library (non-blocking)."""
150+
self._error = "still-loading"
151+
thread = threading.Thread(target=self._load, daemon=True)
152+
thread.start()
153+
146154
def get_load_error(self) -> str:
147155
return str(self._error)
148156

149-
def get_core_version(self) -> str:
150-
return self._version.decode("utf-8") if self._version else self._version
157+
def get_core_version(self) -> str | None:
158+
if self._version:
159+
try:
160+
return self._version.decode("utf-8")
161+
except Exception:
162+
pass
163+
return None
151164

152165

153-
core_loader = _CoreLoader()
166+
_core_loader = _CoreLoader()

src/snowflake/connector/auth/_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
load_pem_private_key,
1818
)
1919

20-
from .._utils import core_loader, get_application_path
20+
from .._utils import _core_loader, get_application_path
2121
from ..compat import urlencode
2222
from ..constants import (
2323
DAY_IN_SECONDS,
@@ -144,8 +144,8 @@ def base_auth_data(
144144
platform_detection_timeout_seconds=platform_detection_timeout_seconds,
145145
session_manager=session_manager.clone(max_retries=0),
146146
),
147-
"CORE_LOAD_ERROR": core_loader.get_load_error(),
148-
"CORE_VERSION": core_loader.get_core_version(),
147+
"CORE_LOAD_ERROR": _core_loader.get_load_error(),
148+
"CORE_VERSION": _core_loader.get_core_version(),
149149
},
150150
},
151151
}

src/snowflake/connector/minicore/__init__.py

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @file sf_mini_core.h
3+
* @brief C API for sf_mini_core library
4+
*
5+
* This header file provides the C API for the sf_mini_core Rust library.
6+
* This file is auto-generated by cbindgen. Do not edit manually!
7+
*/
8+
9+
#ifndef SF_MINI_CORE_H
10+
#define SF_MINI_CORE_H
11+
12+
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually.
13+
*/
14+
15+
#include <stdarg.h>
16+
#include <stdbool.h>
17+
#include <stdint.h>
18+
#include <stdlib.h>
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif // __cplusplus
23+
24+
/**
25+
* Returns the full version string for sf_core.
26+
*
27+
* This function returns a pointer to a static null-terminated string
28+
* containing the version of sf_core.
29+
*
30+
* @return A pointer to a static string containing the version.
31+
* The caller must NOT free this pointer.
32+
* The returned string is valid for the lifetime of the program.
33+
*
34+
* @note Thread-safe: Yes
35+
* @note This function never returns NULL
36+
*
37+
* Example usage:
38+
* @code
39+
* const char* version = sf_core_full_version();
40+
* printf("Version: %s\n", version);
41+
* @endcode
42+
*
43+
* # Safety
44+
*
45+
* The returned pointer points to a static string that is valid for the lifetime
46+
* of the program. The caller must not free the returned pointer.
47+
*/
48+
const char *sf_core_full_version(void);
49+
50+
#ifdef __cplusplus
51+
} // extern "C"
52+
#endif // __cplusplus
53+
54+
#endif /* SF_MINI_CORE_H */

0 commit comments

Comments
 (0)