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

Ошибка при попытке вызова из Google Cloud Functions #154

Closed
leshchenko1979 opened this issue Feb 17, 2022 · 2 comments
Assignees

Comments

@leshchenko1979
Copy link
Owner

Вызывающий код:

bx = fast_bitrix24.Bitrix(user.bitrix_webhook)
Traceback (most recent call last):
  File "/workspace/main.py", line 18, in generate_leads
    return process_request(json)
  File "/workspace/main.py", line 48, in process_request
    add_listings_to_bitrix(listings, user, requested.bitrix_id, test)
  File "/workspace/main.py", line 98, in add_listings_to_bitrix
    bx = fast_bitrix24.Bitrix(user.bitrix_webhook)
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/fast_bitrix24/bitrix.py", line 33, in __init__
    self.srh = ServerRequestHandler(webhook, respect_velocity_policy, client)
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/fast_bitrix24/srh.py", line 72, in __init__
    self.request_complete = Event()
  File "/opt/python3.9/lib/python3.9/asyncio/locks.py", line 177, in __init__
    self._loop = events.get_event_loop()
  File "/opt/python3.9/lib/python3.9/asyncio/events.py", line 642, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'ThreadPoolExecutor-0_0'.
@leshchenko1979 leshchenko1979 self-assigned this Apr 20, 2022
@leshchenko1979
Copy link
Owner Author

Пытаюсь повторить проблему.

Запускаю Google Cloud Function следующего вида:

import asyncio

def ensure_loop():
    try:
        asyncio.get_event_loop()
    except RuntimeError:
        asyncio.set_event_loop(asyncio.new_event_loop())

async def func():
    print("Async func running!")


def hello_world(request):
    caught = False

    print("First try")

    try:
      event = asyncio.Event()    
    except:
      caught = True

    assert caught

    print("First try OK. Second try...")

    ensure_loop()
    event = asyncio.Event()    

    print("Second try OK. Running async...")

    loop = asyncio.get_event_loop()
    loop.run_until_complete(func())

    return "OK"

Получаю ошибку:

 Traceback (most recent call last):
  File "/layers/google.python.pip/pip/lib/python3.10/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/layers/google.python.pip/pip/lib/python3.10/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/layers/google.python.pip/pip/lib/python3.10/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/layers/google.python.pip/pip/lib/python3.10/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/layers/google.python.pip/pip/lib/python3.10/site-packages/functions_framework/__init__.py", line 99, in view_func
    return function(request._get_current_object())
  File "/workspace/main.py", line 23, in hello_world
    assert caught 

То есть,. проблем с получением loop вроде нет.

@leshchenko1979
Copy link
Owner Author

Кроме того, пробуя функцию:

import fast_bitrix24

def hello_world(request):
    bx = fast_bitrix24.Bitrix("XXXXXXX")
    return {"result": bx.call("crm.lead.list", {"select": ["ID"]})}

получаю вполне валидный результат.

Проблему закрываю -- не смог повторить.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant