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: Event loop is closed #992

Open
1 task done
0x30 opened this issue Oct 16, 2024 · 1 comment
Open
1 task done

RuntimeError: Event loop is closed #992

0x30 opened this issue Oct 16, 2024 · 1 comment
Labels

Comments

@0x30
Copy link

0x30 commented Oct 16, 2024

Describe the bug

There is no problem using asyncmy
There is a "RuntimeError: Event loop is closed" error when using aiomysql

Am I using it incorrectly? What's wrong?

To Reproduce

import asyncio
from sqlmodel import SQLModel, Field
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker


class User(SQLModel, table=True):
    id: int = Field(default=None, primary_key=True)


DATABASE_URL = "mysql+asyncmy://root:@localhost:4000/test" ## ✅
DATABASE_URL = "mysql+aiomysql://root:@localhost:4000/test" ## ❌
engine = create_async_engine(DATABASE_URL, echo=True)

AsyncSessionLocal = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)


async def create_db_and_tables():
    async with engine.begin() as conn:
        await conn.run_sync(SQLModel.metadata.create_all)


async def main():
    await create_db_and_tables()


if __name__ == "__main__":
    asyncio.run(main())

Expected behavior

Don't happen RuntimeError: Event loop is closed

Logs/tracebacks

There is no problem using asyncmy
There is a "RuntimeError: Event loop is closed" error when using aiomysql

Python Version

Python 3.12.7

aiomysql Version

0.2.0

PyMySQL Version

1.1.0

SQLAlchemy Version

2.0.36

OS

macOS

Database type and version

8.0.11-TiDB-v7.5.1

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@0x30 0x30 added the bug label Oct 16, 2024
@Ro0tk1t
Copy link

Ro0tk1t commented Nov 8, 2024

same problem, is there any solution?

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

No branches or pull requests

2 participants