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

RuntimeError('There is no current event loop in thread %r.') #58

Closed
simonw opened this issue Jul 23, 2022 · 10 comments
Closed

RuntimeError('There is no current event loop in thread %r.') #58

simonw opened this issue Jul 23, 2022 · 10 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Jul 23, 2022

https://til.simonwillison.net/ site is down at the moment:

image

Logs at https://vercel.com/datasette/simon-til/9SYmpgw4ExnTbRLnsevw5zXXTRgb/functions show:

[ERROR] RuntimeError: There is no current event loop in thread 'MainThread'.Traceback (most recent call last): File "/var/task/vc__handler__python.py", line 453, in vc_handler lifespan = Lifespan(__vc_module.app) File "/var/task/vc__handler__python.py", line 308, in __init__ self.loop = get_event_loop() File "/var/task/vc__handler__python.py", line 184, in get_event_loop return asyncio.get_event_loop() File "/var/lang/lib/python3.9/asyncio/events.py", line 642, in get_event_loop raise RuntimeError('There is no current event loop in thread %r.'

@simonw simonw added the bug Something isn't working label Jul 23, 2022
@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

This could be a new datasette-publish-vercel bug.

@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

Yup, just deployed https://test-if-vercel-publish-broken.vercel.app/ with this and I'm getting the same error:

datasette publish vercel fixtures.db --project 'test-if-vercel-publish-broken'

@simonw simonw transferred this issue from simonw/til Jul 23, 2022
@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

I think this is because of changes to Vercel's Python support.

I happened to have a copy of the working vc__handler__python.py from this morning. I generated a new copy using vercel build and here's the diff:

https://gist.github.com/simonw/8521ba3385279fde4a9878f2ad8d150a/revisions

That diff does indeed show newly added code that calls asyncio.get_running_loop():

         def get_event_loop():
            try:
                return asyncio.get_running_loop()
            except:
                if sys.version_info < (3, 10):
                    return asyncio.get_event_loop()
                else:
                    return asyncio.get_event_loop_policy().get_event_loop()

@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

It looks to me like this commit introduced the bug: vercel/vercel@66c8544

It was supposed to fix an issue in Python 3.10. I'm still running Python 3.9 here - so maybe upgrading to Python 3.10 will work around this issue.

@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

The docs at https://vercel.com/docs/runtimes#official-runtimes/python/python-version suggest that you can't run anything other than Python 3.6 or 3.9.

@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

From the PR at https://github.com/vercel/vercel/pull/8045/files it looks like I might be able to use a Pipfile with python_version = "3.10" in it as a workaround.

@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

I tried a manual deploy using the output from --generate-dir

I had to delete requirements.txt - having both that and Pipfile continued to deploy Python 3.9.

This Pipfile:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
datasette = '0.61.1'

[requires]
python_version = "3.10"

Seems to have worked in that I'm not getting the old error - I think it deployed Python 3.10 though I've not confirmed it yet, because now I get this error instead:

[ERROR] Runtime.ImportModuleError: Unable to import module 'vc__handler__python': No module named 'datasette'

@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

Alternative workaround, maybe try pinning https://www.npmjs.com/package/@vercel/python to 3.0.7?

@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

Here's how to pin that: https://github.com/vercel-support/flask-test/blob/e8b6f669787c5a7a1343c1e78660ea26407c2a0c/vercel.json#L6

{
  "version": 2,
  "builds": [
    {
      "src": "index.py",
      "use": "@vercel/[email protected]"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "/"
    }
  ]
}

@simonw
Copy link
Owner Author

simonw commented Jul 23, 2022

Yes, this seems to fix it:

        "use": "@vercel/[email protected]"

simonw added a commit that referenced this issue Jul 23, 2022
simonw added a commit to simonw/til that referenced this issue Jul 23, 2022
@simonw simonw closed this as completed Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant