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

Make sure that only one cursor possible per connection #24

Open
jettify opened this issue Jul 22, 2015 · 11 comments
Open

Make sure that only one cursor possible per connection #24

jettify opened this issue Jul 22, 2015 · 11 comments

Comments

@jettify
Copy link
Member

jettify commented Jul 22, 2015

We allow multiple cursors per connection, I guess we need to forbid such behaviour and make sure only one cursor possible per connection. There is test that failing on multiple cursors https://github.com/aio-libs/aiomysql/blob/master/tests/test_nextset.py#L53-L73 , should be fixed too.

@asvetlov
Copy link
Member

Sure, by DB API spec there is the only cursor is allowed for connection object in the same time.

@pedrudehuere
Copy link

Hello, I've been playing around with asyncio and used aiomysql for database access, I noticed that coroutines cannot create cursors from a shared connection (like the title of this issue states).
Why is this? because PyMYSQL was not designed for asyncio? will this change in the future or is it just a fact that I should accept?

@asvetlov
Copy link
Member

It's by DB-API design, not specifically PyMYSQL. So yes, you should live with it.

@pedrudehuere
Copy link

Sorry but I cannot find anything that says that, the only thing is this section in the DB API, but it does not mention that only one cursor per connection can exist at any time

@asvetlov
Copy link
Member

Well. It's not stated explicitly. But using non-isolated cursors is dangerous idea at first.
Second, Postgres has the same limitation.
I believe nobody should try to use several cursors for the same connection in parallel.

@pedrudehuere
Copy link

Except for libraries with threadsafety 2 or 3 I guess? (I'm talking about threads here)
But I guess threadsafety does not apply to asyncio

Edit: I see now that PyMSQL has thread-safety level 1

@asvetlov
Copy link
Member

I think it's orthogonal concept.
SQL queries are performed on SQL server side. Usually server uses a thread per connection model and doesn't allow executing several requests for the same connection in parallel internally.

So it's mostly server limitation, not client one.

@pedrudehuere
Copy link

OK I see, thanks

@tvoinarovskyi
Copy link
Member

Should we just add a stub, with an exception if we call connection.cursor() on a connection with active cursor? Will this be enough?

@methane
Copy link
Contributor

methane commented Mar 1, 2016

I think guard like following is enough.

if self._guard:
    raise OperationError("Connection cannot be used in parallel")
self._guard = True
await self._execute_command(...)
await self._read_ok_packet(...)
self._guard = False

@jettify jettify added this to the sprint2016 milestone Jun 2, 2016
@pedro2555
Copy link

pedro2555 commented Oct 9, 2020

If I need to wait for 100 queries. Does this mean I need to call connect() 100 times?

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

No branches or pull requests

7 participants