-
Notifications
You must be signed in to change notification settings - Fork 2
[fix] create a Command-Queue to solve multithread problem #19
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
Conversation
|
now we needs some tests, and then merge it to the current structure of MercurySQL |
There was a problem hiding this 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.
|
creates a Command Queue instead, to solve the multi-thread problem. |
closes #18