Skip to content

fix: remove a usage of the resource package when not available, such as on Windows #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions bigframes/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from collections import namedtuple
from datetime import datetime
import inspect
import resource
import sys
import typing
from typing import (
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -810,12 +816,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___ = [
Expand Down