Skip to content

Conversation

@BernieHuang2008
Copy link
Owner

closes #18

@BernieHuang2008
Copy link
Owner Author

now we needs some tests, and then merge it to the current structure of MercurySQL

Copy link
Owner Author

@BernieHuang2008 BernieHuang2008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm stucked now --- at

# TODO: We can't close the connection in this way.

I can't find a way to close the connection after a certain thread is ended.

I've tried:

  • Create a 'monitor thread'But the connection object can't be closed in the monitor thread since it isn't the creator. And it can't be the creator, since the 'target thread' needs to use the connection.
  • Use threading.local() thread local variables with the clean-up code in a object's 'del()' method. But the garbage collector runs in the main thread, so it doesn't work, either.
  • We can't hope that users will manually close the connection. Because if they forgot to do so, we cannot help them. It will cause a serious problem. (after all, i myself often forget such things)

Another solution that can work, but will effect the performance:

  • A single-use connection: Start a new connection, execute a single query, and close it.
    It will hugely reduce the performance, since the MSQL itself will execute a loads of queries to gather information.

Now it's only one solution --- that is, use with statement. But it will effect the UX greatly and needs a lot of changes in codes.

@BernieHuang2008
Copy link
Owner Author

creates a Command Queue instead, to solve the multi-thread problem.

@BernieHuang2008 BernieHuang2008 changed the title create connection pool [fix] create a Command-Queue to solve multithread problem Jul 1, 2024
@BernieHuang2008 BernieHuang2008 marked this pull request as ready for review July 1, 2024 14:58
@BernieHuang2008 BernieHuang2008 merged commit 3aa96d4 into main Jul 1, 2024
@BernieHuang2008 BernieHuang2008 deleted the orm-connpool branch July 1, 2024 14:59
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

Successfully merging this pull request may close these issues.

[bug] Cannot operate SQLite3 in multi-thread case

2 participants