Skip to content

Commit 7e29e63

Browse files
author
Dan King
committed
Merge branch 'allow-timeout-as-number' into new-new-copier
2 parents 5d1be8c + 630ffd3 commit 7e29e63

File tree

4 files changed

+66
-13
lines changed

4 files changed

+66
-13
lines changed

hail/Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ $(FAST_PYTHON_JAR_EXTRA_CLASSPATH): build.gradle
181181
python-jar: $(PYTHON_JAR)
182182

183183
.PHONY: pytest
184-
pytest: $(PYTHON_VERSION_INFO) $(INIT_SCRIPTS)
185-
pytest: python/README.md $(FAST_PYTHON_JAR) $(FAST_PYTHON_JAR_EXTRA_CLASSPATH)
184+
pytest: install-editable
186185
cd python && \
187186
$(HAIL_PYTHON3) -m pytest \
188187
-Werror:::hail -Werror:::hailtop -Werror::ResourceWarning \
@@ -202,8 +201,7 @@ pytest: python/README.md $(FAST_PYTHON_JAR) $(FAST_PYTHON_JAR_EXTRA_CLASSPATH)
202201

203202
# NOTE: Look at upload-remote-test-resources target if test resources are missing
204203
.PHONY: pytest-inter-cloud
205-
pytest-inter-cloud: install-editable
206-
pytest-inter-cloud: upload-remote-test-resources
204+
pytest-inter-cloud: upload-remote-test-resources install-editable
207205
cd python && \
208206
HAIL_TEST_STORAGE_URI=$(TEST_STORAGE_URI) \
209207
HAIL_TEST_GCS_BUCKET=$(HAIL_TEST_GCS_BUCKET) \
@@ -349,15 +347,20 @@ upload-artifacts: $(WHEEL)
349347
# NOTE: 1-day expiration of the test bucket means that this
350348
# target must be run at least once a day. To trigger this target to re-run,
351349
# > rm upload-remote-test-resources
350+
upload-remote-test-resources: install-editable
352351
upload-remote-test-resources: $(shell git ls-files src/test/resources)
353352
upload-remote-test-resources: $(shell git ls-files python/hail/docs/data)
354353
# # If hailtop.aiotools.copy gives you trouble:
355354
# gcloud storage cp -r src/test/resources/\* $(CLOUD_HAIL_TEST_RESOURCES_DIR)
356355
# gcloud storage cp -r python/hail/docs/data/\* $(CLOUD_HAIL_DOCTEST_DATA_DIR)
357-
python3 -m hailtop.aiotools.copy -vvv 'null' '[\
358-
{"from":"src/test/resources","to":"$(CLOUD_HAIL_TEST_RESOURCES_DIR)"},\
359-
{"from":"python/hail/docs/data","to":"$(CLOUD_HAIL_DOCTEST_DATA_DIR)"}\
360-
]' --timeout 600
356+
python3 -m hailtop.aiotools.copy \
357+
-vvv \
358+
'null' \
359+
"[\
360+
{\"from\":\"src/test/resources\",\"to\":\"$(CLOUD_HAIL_TEST_RESOURCES_DIR)\"}, \
361+
{\"from\":\"python/hail/docs/data\",\"to\":\"$(CLOUD_HAIL_DOCTEST_DATA_DIR)\"} \
362+
]" \
363+
--timeout 600
361364
touch $@
362365

363366
# NOTE: 1-day expiration of the test bucket means that this

hail/python/hailtop/aiocloud/aioaws/fs.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
from typing import Any, AsyncIterator, BinaryIO, cast, AsyncContextManager, Dict, List, Optional, Set, Tuple, Type
1+
from typing import (
2+
Any,
3+
AsyncIterator,
4+
BinaryIO,
5+
cast,
6+
AsyncContextManager,
7+
Dict,
8+
List,
9+
Optional,
10+
Set,
11+
Tuple,
12+
Type,
13+
Union,
14+
)
215
from types import TracebackType
16+
import aiohttp
317
import sys
418
from concurrent.futures import ThreadPoolExecutor
519
import os.path
@@ -341,12 +355,32 @@ def __init__(
341355
max_workers: Optional[int] = None,
342356
*,
343357
max_pool_connections: int = 10,
358+
timeout: Optional[Union[int, float, aiohttp.ClientTimeout]] = None,
344359
):
345360
if not thread_pool:
346361
thread_pool = ThreadPoolExecutor(max_workers=max_workers)
347362
self._thread_pool = thread_pool
363+
364+
kwargs = {}
365+
if isinstance(timeout, aiohttp.ClientTimeout):
366+
if timeout.sock_read:
367+
kwargs['read_timeout'] = timeout.sock_read
368+
elif timeout.total:
369+
kwargs['read_timeout'] = timeout.total
370+
371+
if timeout.sock_connect:
372+
kwargs['connect_timeout'] = timeout.sock_connect
373+
elif timeout.connect:
374+
kwargs['connect_timeout'] = timeout.connect
375+
elif timeout.total:
376+
kwargs['connect_timeout'] = timeout.total
377+
elif isinstance(timeout, (int, float)):
378+
kwargs['read_timeout'] = timeout
379+
kwargs['connect_timeout'] = timeout
380+
348381
config = botocore.config.Config(
349382
max_pool_connections=max_pool_connections,
383+
**kwargs,
350384
)
351385
self._s3 = boto3.client('s3', config=config)
352386

hail/python/hailtop/aiocloud/aioazure/fs.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, AsyncContextManager, AsyncIterator, Dict, List, Optional, Set, Tuple, Type, Union
22
from types import TracebackType
33

4+
import aiohttp
45
import abc
56
import re
67
import os
@@ -372,7 +373,13 @@ async def wrapped(self: 'AzureAsyncFS', url, *args, **kwargs):
372373
class AzureAsyncFS(AsyncFS):
373374
PATH_REGEX = re.compile('/(?P<container>[^/]+)(?P<name>.*)')
374375

375-
def __init__(self, *, credential_file: Optional[str] = None, credentials: Optional[AzureCredentials] = None):
376+
def __init__(
377+
self,
378+
*,
379+
credential_file: Optional[str] = None,
380+
credentials: Optional[AzureCredentials] = None,
381+
timeout: Optional[Union[int, float, aiohttp.ClientTimeout]] = None,
382+
):
376383
if credentials is None:
377384
scopes = ['https://storage.azure.com/.default']
378385
if credential_file is not None:
@@ -382,6 +389,16 @@ def __init__(self, *, credential_file: Optional[str] = None, credentials: Option
382389
elif credential_file is not None:
383390
raise ValueError('credential and credential_file cannot both be defined')
384391

392+
if isinstance(timeout, aiohttp.ClientTimeout):
393+
self.read_timeout = timeout.sock_read or timeout.total or 5
394+
self.connection_timeout = timeout.sock_connect or timeout.connect or timeout.total or 5
395+
elif isinstance(timeout, (int, float)):
396+
self.read_timeout = timeout
397+
self.connection_timeout = timeout
398+
else:
399+
self.read_timeout = 5
400+
self.connection_timeout = 5
401+
385402
self._credential = credentials.credential
386403
self._blob_service_clients: Dict[Tuple[str, str, Union[AzureCredentials, str, None]], BlobServiceClient] = {}
387404

@@ -482,8 +499,8 @@ def get_blob_service_client(self, account: str, container: str, token: Optional[
482499
self._blob_service_clients[k] = BlobServiceClient(
483500
f'https://{account}.blob.core.windows.net',
484501
credential=credential, # type: ignore
485-
connection_timeout=5,
486-
read_timeout=5,
502+
connection_timeout=self.connection_timeout,
503+
read_timeout=self.read_timeout,
487504
)
488505
return self._blob_service_clients[k]
489506

hail/python/hailtop/aiotools/copy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ async def main() -> None:
200200
timeout = args.timeout
201201
if timeout:
202202
timeout = float(timeout)
203-
print(timeout)
204203
gcs_kwargs = {
205204
'gcs_requester_pays_configuration': requester_pays_project,
206205
'timeout': timeout,

0 commit comments

Comments
 (0)