Accessing MySQL from multiple views of a web site

86 Views Asked by At

I am writing a web tool using Python and Pyramid. It access a MySQL database using MySQLdb and does queries based on user input. I created a user account for the tool and granted it read access on the tables it uses.

It works fine when I open the page in a single tab, but if I try loading it in second tab the page won't load until the first search is finished. Is there a way to get around this or am I just trying to use MySQL incorrectly?

1

There are 1 best solutions below

3
On BEST ANSWER

What @AlexIvanov is trying to say is that when you're starting your Pyramid app in console it is served using Pyramid's built-in development server. This server is single-threaded and serves requests one after another, so if you have a long request which takes, say, 15 seconds - you won't be able to use your app in another tab until that long request finishes. This sequential nature of the built-in webserver is actually an awesome feature which greatly simplifies debugging.

In production, your Pyramid app is normally served by a "real" webserver, such as Apache or Nginx. Such webservers normally spawn multiple "workers", or use multiple threads which allow them to serve multiple concurrent requests.

So I suspect there's nothing wrong with your setup (provided you didn't do anything particularly strange with Pyramid's initial scaffold and it's still using SQLAlchemy's session configured with ZopeTransactionExtension etc.).

A "single shared MySQL account" in no way prevents multiple connected clients from running queries concurrently in MySQL - the thing is, with the development server you only have one single-threaded client.