Skip to content

Commit b34717f

Browse files
disabling parallel download for windows
1 parent 4a41ae4 commit b34717f

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

databricks/sdk/mixins/files.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,13 @@ def download_to(
836836
if not overwrite and os.path.exists(destination):
837837
raise FileExistsError(destination)
838838
if use_parallel:
839+
# Parallel download is not supported for Windows due to the limit of only one open file handle
840+
# for writing. If parallel download is requested on Windows, fall back to sequential download with
841+
# a warning.
842+
if platform.system() == "Windows":
843+
_LOG.warning("Parallel download is not supported on Windows. Falling back to sequential download.")
844+
self._sequential_download_to_file(destination, remote_path=file_path)
845+
return DownloadFileResult()
839846
if parallelism is None:
840847
parallelism = self._config.files_ext_parallel_download_default_parallelism
841848
if parallelism < 1 or parallelism > 64:

tests/test_files.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
import json
55
import logging
66
import os
7+
import platform
78
import random
89
import re
910
import time
1011
from dataclasses import dataclass
1112
from datetime import datetime, timedelta, timezone
1213
from enum import Enum
13-
from tempfile import NamedTemporaryFile, mkstemp
14+
from tempfile import NamedTemporaryFile
1415
from threading import Lock
1516
from typing import Any, Callable, List, Optional, Type, Union
1617
from urllib.parse import parse_qs, urlparse
@@ -199,6 +200,8 @@ def to_string(test_case: "FilesApiDownloadTestCase") -> str:
199200
return test_case.name
200201

201202
def run(self, config: Config, monkeypatch) -> None:
203+
if self.use_parallel and platform.system() == "Windows":
204+
pytest.skip("Skipping parallel download tests on Windows")
202205
config = config.copy()
203206
config.enable_experimental_files_api_client = self.enable_new_client
204207
config.files_ext_client_download_max_total_recovers = self.max_recovers_total
@@ -935,6 +938,9 @@ def processor() -> list:
935938
raise RuntimeError("Unexpected request " + str(request))
936939

937940
def run_one_case(self, config: Config, monkeypatch, download_mode: DownloadMode, use_parallel: bool) -> None:
941+
if use_parallel and platform.system() == "Windows":
942+
logger.debug("Parallel download is not supported on Windows. Falling back to sequential download.")
943+
return
938944
config = config.copy()
939945
config.enable_experimental_files_api_client = True
940946
config.enable_presigned_download_api = True
@@ -1149,7 +1155,8 @@ def save_part(self, part_number: int, part_content: bytes, etag: str) -> None:
11491155
# part might already have been uploaded
11501156
with self.global_lock:
11511157
if part_number not in self.uploaded_parts:
1152-
fd, part_file = mkstemp()
1158+
with NamedTemporaryFile(mode="wb", delete=False) as f:
1159+
part_file = f.name
11531160
self.uploaded_parts[part_number] = [part_file, etag, Lock()]
11541161
existing_part = self.uploaded_parts[part_number]
11551162
with existing_part[2]: # lock per part
@@ -1275,9 +1282,9 @@ def clear_state(self) -> None:
12751282
def get_upload_file(self, content: bytes, source_type: "UploadSourceType") -> Union[str, io.BytesIO]:
12761283
"""Returns a file or stream to upload based on the source type."""
12771284
if source_type == UploadSourceType.FILE:
1278-
fd, file_path = mkstemp()
1279-
with open(fd, "wb") as f:
1285+
with NamedTemporaryFile(mode="wb", delete=False) as f:
12801286
f.write(content)
1287+
file_path = f.name
12811288
self.created_temp_files.append(file_path)
12821289
return file_path
12831290
elif source_type == UploadSourceType.STREAM:
@@ -2211,8 +2218,8 @@ def save_part(self, start_offset: int, end_offset_incl: int, part_content: bytes
22112218
if unconfirmed_delta > 0:
22122219
part_content = part_content[:-unconfirmed_delta]
22132220

2214-
fd, part_file = mkstemp()
2215-
with open(fd, "wb") as f:
2221+
with NamedTemporaryFile(mode="wb", delete=False) as f:
2222+
part_file = f.name
22162223
f.write(part_content)
22172224

22182225
self.uploaded_parts.append(part_file)

0 commit comments

Comments
 (0)