Tornado multiple processes: create multiple MySQL connections
<p>I'm running a Tornado HTTPS server across multiple processes using the first method described here <a href="http://www.tornadoweb.org/en/stable/guide/running.html" rel="nofollow">http://www.tornadoweb.org/en/stable/guide/running.html</a> (server.start(n))</p>

<p>The server is connected to a local MySQL instance and I would like to have a independent MySQL connection per Tornado process.</p>

<p>However, right now I only have one MySQL connection according to the output of SHOW PROCESSLIST. I guess this happens because I establish the connection before calling server.start(n) and IOLoop.current().start() right?</p>

<p>What I don't really understand is whether the processes created after calling server.start(n) share some data (for instance, global variables within the same module) or are totally independent.</p>

<p>Should I establish the connection after calling server.start(n) ? Or after calling IOLoop.current().start() ? If I do so, will I have one MySQL connection per Tornado process?</p>

<p>Thanks</p>

<p>Each child process gets a copy of the variables that existed in the parent process when <code>start(n)</code> was called. For things like connections, this will usually cause problems. When using multi-process mode, it's important to do as little as possible before starting the child processes, so don't create the mysql connections until after <code>start(n)</code> (but before <code>IOLoop.start()</code>; <code>IOLoop.start()</code> doesn't return until the server is stopped). </p>

python mysql multiprocessing tornado multiprocess