[Pythonmac-SIG] py2app & multiprocessing

Alexandre Quessy alexandre at quessy.net
Thu Aug 20 14:06:11 CEST 2009


Hi again,
I think using multiprocessing should be the way to go, so that you use
twisted for the main event loop in one process, and wx for the main
event loop in the other.

In a simple way, you can also build your own custom multiprocessing
tool. You just need one system calls, and one network connection. (for
controlling the other process) Like this :

pid = os.fork()
if pid == 0: # child
    # no need to call os.execv(), since your code is in python
    # open TCP socket as a receiver
    # start event loop
else: # child
    child_pid = pid
    # open TCP socket as a sender
    # start event loop

...and no, I am not using twistd. For now, I prefer not to rely on any
other executable, and start the main loop in my app.

reactor.run()

You can also look at some other free software I am working on :
 * Lunch : https://svn.sat.qc.ca/trac/postures/wiki/Lunch
 * ToonLoop : http://www.toonloop.com/
 * Miville : https://svn.sat.qc.ca/trac/miville
 * RawMaterials : https://svn.sat.qc.ca/trac/rawmaterials

They all use twisted, but RawMaterials is the only for Mac. (the code
is rather old and should be updated.) ToonLoop should be ported to mac
with a app bundle soon. It is a live stop motion software, which is
also the topic of my master.

What does your application do ? Is it free software as well ?
Ciao,
-- 
Alexandre Quessy
http://alexandre.quessy.net/





2009/8/20 Gabriel Rossetti <gabriel.rossetti at arimaz.com>:
> Hello Alexandre,
>
> His is how I had it before, but it was causing me problems and I was told
> that it's better tu run them in separate threads. Do you use twistd (.tac
> files)? I'll have a look at your application, thanks!
>
> Gabriel
>
> Alexandre Quessy wrote:
>>
>> Hi everyone,
>> I use Twisted everyday, and have worked on a wx GUI for an application
>> using it. We also use Py2App to bundle it up. It works flawlessly. I
>> use the Twisted main loop, which controls the wx events loop.
>>
>> To make both of them work together, you need to do the following :
>>
>> {{{
>> from twisted.internet import wxreactor
>> wxreactor.install()
>> }}}
>>
>> You can check our RawMaterials application since it is free software.
>> It has a lot of dependencies, so it is rather difficult to build.
>> https://svn.sat.qc.ca/trac/rawmaterials/browser/trunk/src/RawMaterials.py
>> We use a shell script to build and copy things in the .app :
>> https://svn.sat.qc.ca/trac/rawmaterials/browser/trunk/src/make_app.sh
>>
>> I would say the problem is probably more about multiprocessing than wx
>> and twisted. Using subprocess, or pexpect, or commands might be a
>> better idea.
>>
>> a
>>
>> 2009/8/14 Gabriel Rossetti <gabriel.rossetti at arimaz.com>:
>>
>>>
>>> Christopher Barker wrote:
>>>
>>>>
>>>> Gabriel Rossetti wrote:
>>>>
>>>>>
>>>>> no SSH, nothing) and I have to had reboot it. It uses a combination of
>>>>> Twisted and wxPython and is rather large, so I don't know where this
>>>>> comes
>>>>> from, it could be wx, twisted or the two together.
>>>>>
>>>>
>>>> It's probably not wx -- it is used a fair bit on Macs.
>>>>
>>>> I don't know how much Twisted is used on the Mac. It might be worth
>>>> asking
>>>> on a Twisted list. Also, have you tried just a simple Twisted app on its
>>>> own?
>>>>
>>>> And yes, I suppose the two together could be an issue.
>>>>
>>>
>>> Yes actually, it was the two together. I used something someone had told
>>> me
>>> about a some time ago, that is to use the wx eventloop as the main
>>> eventloop
>>> and have twisted's run in a separate thread, it now works fine on Mac.
>>>
>>> I'm still working on the pz2app part though, I'll kep everyone updated.
>>>
>>> Gabriel
>>>
>>>
>>>>
>>>> Oh, and do you have these problems running without py2app?
>>>>
>>>>
>>>>>
>>>>> Popen could not find my files when using py2app,
>>>>>
>>>>
>>>> This should be a simple path issue -- a few judicious print statements
>>>> should help here.
>>>>
>>>>
>>>>>
>>>>> even though they were in the same
>>>>>
>>>>> directory as the main exec. I even tried putting the execs in the
>>>>> resource dir but no luck,
>>>>>
>>>>
>>>> hmm -- I think that is indeed where the working dir is set by py2app
>>>> when
>>>> starting op. try:
>>>>
>>>> print os.getcwd()
>>>>
>>>> you can look in the "Console" app to see stuff printed to stdout.
>>>>
>>>> -Chris
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
>>> http://mail.python.org/mailman/listinfo/pythonmac-sig
>>>
>>>
>>
>>
>>
>>
>


More information about the Pythonmac-SIG mailing list