From fc102610c87466728404bb87fbbd4480ebcad0db Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Fri, 10 May 2024 21:49:43 +0000 Subject: [PATCH] fix: remove a usage of the `resource` package when not available, such as on Windows --- bigframes/pandas/__init__.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bigframes/pandas/__init__.py b/bigframes/pandas/__init__.py index 1d6da46fae..13cde0335d 100644 --- a/bigframes/pandas/__init__.py +++ b/bigframes/pandas/__init__.py @@ -19,7 +19,6 @@ from collections import namedtuple from datetime import datetime import inspect -import resource import sys import typing from typing import ( @@ -70,6 +69,13 @@ import bigframes.session._io.bigquery import bigframes.session.clients +try: + import resource +except ImportError: + # resource is only available on Unix-like systems. + # https://docs.python.org/3/library/resource.html + resource = None # type: ignore + # Include method definition so that the method appears in our docs for # bigframes.pandas general functions. @@ -808,12 +814,13 @@ def clean_up_by_session_id( # https://github.com/python/cpython/issues/112282 sys.setrecursionlimit(max(10000000, sys.getrecursionlimit())) -soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_STACK) -if soft_limit < hard_limit or hard_limit == resource.RLIM_INFINITY: - try: - resource.setrlimit(resource.RLIMIT_STACK, (hard_limit, hard_limit)) - except Exception: - pass +if resource is not None: + soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_STACK) + if soft_limit < hard_limit or hard_limit == resource.RLIM_INFINITY: + try: + resource.setrlimit(resource.RLIMIT_STACK, (hard_limit, hard_limit)) + except Exception: + pass # Use __all__ to let type checkers know what is part of the public API. __all___ = [