1
1
from __future__ import annotations
2
2
3
- import functools
4
3
import logging
5
4
import threading
6
5
import warnings
7
- import weakref
8
6
from typing import TYPE_CHECKING , Optional , Protocol , Tuple , Type , TypedDict , Union
9
7
10
8
import numpy as np
@@ -32,16 +30,6 @@ def _curthread():
32
30
return threading .current_thread ().name
33
31
34
32
35
- def log_event (topic : str , msg : dict ) -> None :
36
- try :
37
- import distributed
38
-
39
- worker = distributed .get_worker ()
40
- except (ImportError , ValueError ):
41
- return
42
- worker .log_event (topic , dict (msg , thread = _curthread ()))
43
-
44
-
45
33
# /TODO
46
34
47
35
@@ -203,8 +191,6 @@ def __init__(
203
191
# but because `close` closes datasets across all threads by simply deleting the current threadlocal
204
192
# and replacing it with an empty one, we have to synchronize all access to `self._threadlocal`.
205
193
206
- log_event ("create_ThreadLocalRioDataset" , dict (url = self ._url , vrt = bool (vrt )))
207
-
208
194
def _open (self ) -> Union [SelfCleaningDatasetReader , WarpedVRT ]:
209
195
with self ._env .open :
210
196
with time (f"Reopen { self ._url !r} in { _curthread ()} : {{t}}" ):
@@ -214,23 +200,16 @@ def _open(self) -> Union[SelfCleaningDatasetReader, WarpedVRT]:
214
200
driver = self ._driver ,
215
201
** self ._open_options ,
216
202
)
217
- log_event ("open_dataset" , dict (url = self ._url ))
218
203
if self ._vrt_params :
219
204
with self ._env .open_vrt :
220
205
result = vrt = WarpedVRT (ds , sharing = False , ** self ._vrt_params )
221
- log_event ("open_vrt" , dict (url = self ._url ))
222
206
else :
223
207
vrt = None
224
208
225
209
with self ._lock :
226
210
self ._threadlocal .ds = ds
227
211
self ._threadlocal .vrt = vrt
228
212
229
- weakref .ref (
230
- ds , functools .partial (log_event , "close_dataset" , dict (url = self ._url ))
231
- )
232
- weakref .ref (vrt , functools .partial (log_event , "close_vrt" , dict (url = self ._url )))
233
- # NOTE: functools.partial to hopefully avoid taking a closure over `self`
234
213
return result
235
214
236
215
@property
@@ -277,7 +256,6 @@ def close(self) -> None:
277
256
# datasets.
278
257
# NOTE: we're assuming here that closing a GDAL dataset from a thread other than the one that created
279
258
# it is safe to do, which, knowing GDAL, is quite possibly untrue.
280
- log_event ("close_ThreadLocalRioDataset" , dict (url = self ._url ))
281
259
with self ._lock :
282
260
self ._threadlocal = threading .local ()
283
261
@@ -365,14 +343,6 @@ def _open(self) -> ThreadsafeRioDataset:
365
343
"a separate STAC asset), so you'll need to exclude this asset from your analysis."
366
344
)
367
345
368
- log_event ("open_dataset_initial" , dict (url = self .url ))
369
- weakref .ref (
370
- ds ,
371
- functools .partial (
372
- log_event , "close_dataset_initial" , dict (url = self .url )
373
- ),
374
- )
375
-
376
346
# Only make a VRT if the dataset doesn't match the spatial spec we want
377
347
if self .spec .vrt_params != {
378
348
"crs" : ds .crs .to_epsg (),
@@ -387,13 +357,6 @@ def _open(self) -> ThreadsafeRioDataset:
387
357
resampling = self .resampling ,
388
358
** self .spec .vrt_params ,
389
359
)
390
- log_event ("open_vrt_initial" , dict (url = self .url ))
391
- weakref .ref (
392
- vrt ,
393
- functools .partial (
394
- log_event , "close_vrt_initial" , dict (url = self .url )
395
- ),
396
- )
397
360
else :
398
361
logger .info (f"Skipping VRT for { self .url !r} " )
399
362
vrt = None
0 commit comments