Creating a new Qapplication from Qapplication event loop
<p>I have rewritten the question so that it is more clear.</p>

<p>In my code I created a QApplication, connected a slot to the application using QTimer.singleShot(), then executed my application.</p>

<p>Now in this slot I want to create another QApplication in another process, I used multiprocessing.Process Class and from inside the process I try to start another QApplication and execute it, but I have an error because an event loop is already running!, I know I can't run two event loops but I am running the new QApplication in another process so it should run.</p>

<p>I know this is not a common implementation but it would be much easier to get this running in my case.</p>

<p>Here is a code example:
The error I get is "QCoreApplication::exec: The event loop is already running"</p>

<pre><code>import multiprocessing
from PyQt4 import QtCore,QtGui

def first_app_slot():
    mProcess = multiprocessing.Process(target = run_another_app)
    mProcess.start()
    mProcess.join()

def run_another_app():
    second_app = QtGui.QApplication([])
    second_app.exec_()

if __name__ == "__main__":
    first_app = QtGui.QApplication([])
    QtCore.QTimer.singleShot(0,first_app_slot)
    first_app.exec_()
</code></pre>

<p>A few problems</p>

<ol>
<li><p>In your code, you're not calling any of the multiprocessing code (maybe a typo)?</p></li>
<li><p>Don't create the first <code>QApplication</code> in the global scope, put it inside a function.  Before creating a new process, <code>multiprocessing</code> will copy the global state to the new process, which includes <code>first_app</code> in this case.  </p></li>
</ol>

<p>Ex.</p>

<pre><code>def main():
    first_app = QtGui.QApplication(sys.argv)
    ...

if __name__ == '__main__':
    main()
</code></pre>

python qt pyqt multiprocessing qapplication