8000 fix: remove a usage of the `resource` package when not available, such as on Windows by tswast · Pull Request #681 · googleapis/python-bigquery-dataframes · GitHub
[go: up one dir, main page]

Skip to content
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
0