-
Notifications
You must be signed in to change notification settings - Fork 55
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
RuntimeError: can't create new thread at interpreter shutdown #850
Comments
@ankitarya1019 I've seen this issue on my end running something on GCE whose main function ends with a |
I have the same issue when I configure Python logger for Cloud Function as advised on this page: I am using Python Here is the stack trace:
|
@tsaluszewski Could you post the script that you used to get the stack trace? I've been able to reproduce it on my end and I'm just curious what you did. Since you followed the quick start guide, is it something along the lines of
|
Yes, very similar, see below my
import logging
from logging import Logger
LOG_FORMAT = "%(asctime)s |%(levelname)s| (%(module)s):%(lineno)s >> %(message)s"
def setup_logger(log_level: str, enable_cloud_logging: bool) -> Logger:
"""
Setup root logger only once, module level loggers will inherit its configuration.
:param log_level: logging level
:param enable_cloud_logging: whether to enable google cloud logging
:returns: pre-configured root logger
"""
if enable_cloud_logging:
setup_cloud_logging(log_level)
logging.basicConfig(format=LOG_FORMAT, level=log_level)
logger = logging.getLogger()
return logger
def setup_cloud_logging(log_level: str) -> None:
"""
Attach the Cloud Logging handler to the Python root logger as described below:
- https://cloud.google.com/logging/docs/setup/python
:param log_level: logging level
"""
from google.cloud.logging import Client
# Instantiates a client
client = Client()
# Retrieves a Cloud Logging handler based on the environment you're running in
# and integrates the handler with the Python logging module
client.setup_logging(log_level=log_level) Notes:
import functions_framework
from common.logger import setup_logger
from common.models import Config
from common.typings import EventRequest
config = Config()
logger = setup_logger(config.log_level, config.is_cloud)
@functions_framework.http
def run(request: EventRequest) -> str:
"""
Function entry point.
:param request: request payload
"""
logger.info(f"Invoked with event={str(request)}")
.... |
@tsaluszewski I wasn't able to reproduce this deploying on Cloud Functions, as |
This is still presenting an issue. My gross workaround for now it is to stick a |
Below is the setup that works for me: logger.py
config.py
Major points:
|
Environment details
Cloud Run with google-cloud-logging==3.9.0
Steps to reproduce
(print statements swapped with logger.info )
Code example
Stack trace
most similar issue I could find: #21. but there is no clear resolution
The text was updated successfully, but these errors were encountered: