如何为Google云端函数的Python 3.8运行时查找“ invoke_user_function”函数

问题描述

我目前正在处理一个个人项目,该项目需要我访问Google Cloud Functions的运行时参数。 Google Cloud功能 目前支持2个运行时,Python 3.7和Python 3.8。

我为Python 3.7运行时编写了以下代码:-

from google.cloud import functions as func

def hello_world(request):
    print(dir(func))
    print(dir(func.worker_v1))
    print(dir(func.worker_v1.FunctionHandler))

我得到以下输出:-

[
'_USE_WORKER_V2','_USE_WORKER_V2_VAR','__annotations__','__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__spec__','os','worker_v1','worker_v2'
]

[
'FunctionHandler','HTTPException','LogBuffer','LogInfo','LoggingWorker','NoLoggingWSGIRequestHandler','TEMPLATE_FOLDER','WSGIRequestHandler','WSGIServer','_CODE_LOCATION','_CONTAINER_LOGGING_ENABLED','_CRASH','_ENTRY_POINT','_EXECUTE_PREFIX','_Event','_FUNCTION_NAME','_FUNCTION_STATUS_HEADER_FIELD','_FUNCTION_TRIGGER_TYPE','_FUNCTION_VERSION','_GOOGLE_CLOUD_DEBUG_ENABLED','_GOOGLE_CLOUD_TRACE_ENABLED','_GOOGLE_CONTAINER_LOGGING_ENABLED','_HTTP_TRIGGER','_IPv6Server','_LOAD_ERROR','_MAX_LOG_BATCH_ENTRIES','_MAX_LOG_BATCH_LENGTH','_MAX_LOG_LENGTH','_SUPERVISOR_HOSTNAME','_SUPERVISOR_INTERNAL_PORT','_SUPERVISOR_LOG_PERIOD_SEC','_SUPERVISOR_LOG_TIMEOUT_SEC','_TRACER','_TRACE_ENABLED','_URL_PATTERN','_WORKER_PORT','_adjust_response_with_trace_header','_adjust_trace_span','_adjust_user_request','_datetime_now_utc','_ensure_leading_slash','_function_handler','_remove_prefix','_url_with_slash_after_hostname','app','asyncio','check_or_load_user_function','check_worker','collections','datetime','event_context','flask','io','json','logging','main','make_server','post_to_supervisor','queue','re','redirect_stdout_and_stderr','requests','routing','run_background_function','setup_logging','signal','socket','sys','threading','time','traceback','try_enable_tracing','util'
]

[
'__class__','__delattr__','__dict__','__dir__','__eq__','__format__','__ge__','__getattribute__','__gt__','__hash__','__init__','__init_subclass__','__le__','__lt__','__module__','__ne__','__new__','__reduce__','__reduce_ex__','__repr__','__setattr__','__sizeof__','__str__','__subclasshook__','__weakref__','_user_function','flush','has_user_function','invoke_user_function','load_user_function','log_user_error'
]

如您在上面看到的,有一个“ invoke_user_function”函数,它是我需要的确切函数。

现在,对于Python3.7运行时环境,我得到了这些结果,但是对于Python 3.8,我没有得到这些结果。

对于Python 3.8运行时,我编写了以下代码:-

from google.cloud import functions as func

def hello_world(request):
    print(dir(func))
    print(dir(func.context))
    return "string"

我得到以下输出:-


['Context','__spec__']

在Python3.8运行时,我无处获得我的项目需要的“ invoke_user_function”功能。

重要问题:有没有人以前遇到过这种情况,并且知道在使用Python3.8的情况下该在哪里找到?

解决方法

我已经复制了此内容,因此可以确认它没有作用。但是Python 3.8 runtime处于Beta阶段,因此尚未准备就绪。

如果需要,您可以尝试转到支持页面第Beta tester group页 这应该是提出这个问题的更好的地方。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...