hi
I have a program in python that does graphics and talks to PD via OSC. Up to now i have run manually both the python app and the PD file. BUt now I am trying to launch PD from the python code but i cannot make it work.
My understanding is that i should use some command from python os module such as spawnl() so that it opens the process of launching without bocking the python graphics.
The system is OSX 10.3.9 and PD is copied next to the main python file that i am running. I am doing some basic tests now that that look more or less like this.
# execdir = os.path.dirname(sys.argv[0]) pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/MacOS/Pd") arg = os.path.join(execdir, "audio.pd") os.spawnl(os.P_NOWAIT, pdexc, arg) # etc ...
Any tips about this? i dont understand why this is not doing its work. Probably I am missing some important detail...
thanks
# execdir = os.path.dirname(sys.argv[0]) pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/MacOS/Pd") arg = os.path.join(execdir, "audio.pd") os.spawnl(os.P_NOWAIT, pdexc, arg) # etc ...
try with pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/Resources/bin/pd")
nico(e)k dio:
# execdir = os.path.dirname(sys.argv[0]) pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/MacOS/Pd") arg = os.path.join(execdir, "audio.pd") os.spawnl(os.P_NOWAIT, pdexc, arg) # etc ...
try with pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/Resources/bin/pd")
i already did but it doesnt work at all. Pointing into "/Pd-0.38-4-extended-RC1.app/Contents/MacOS/Pd" at least does open a console and a window like the main Pd window but it is called audio.pd it seems to be confused, it opens pd with the name of the file that PD should open??
weird, it looks like some Tcl console or similar.
i keep searching
# execdir = os.path.dirname(sys.argv[0]) pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/MacOS/Pd") arg = os.path.join(execdir, "audio.pd") os.spawnl(os.P_NOWAIT, pdexc, arg) # etc ...
try with pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/Resources/bin/pd")
actually, I think if the Pd-0.38-4-extended-RC1.app is in the same directory where you start python, then you want to try something like this: pdexc = os.path.join(execdir, "./Pd-0.38-4-extended-RC1.app/Contents/Resources/bin/pd")
^ | | -> notice the "./"
-august.
august(e)k dio:
# execdir = os.path.dirname(sys.argv[0]) pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/MacOS/Pd") arg = os.path.join(execdir, "audio.pd") os.spawnl(os.P_NOWAIT, pdexc, arg) # etc ...
try with pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/Resources/bin/pd")
actually, I think if the Pd-0.38-4-extended-RC1.app is in the same directory where you start python, then you want to try something like this: pdexc = os.path.join(execdir, "./Pd-0.38-4-extended-RC1.app/Contents/Resources/bin/pd")
^ | | -> notice the "./"
hi august
i tried and it doesnt seem to make any difference. Looks like Python doesnt like something about PD.
thanks
-august.
actually, I think if the Pd-0.38-4-extended-RC1.app is in the same directory where you start python, then you want to try something like this: pdexc = os.path.join(execdir, "./Pd-0.38-4-extended-RC1.app/Contents/Resources/bin/pd")
^ | | -> notice the "./"
hi august
i tried and it doesnt seem to make any difference. Looks like Python doesnt like something about PD.
nico,
sorry, I wrote that email early in the morning. the only reason for doing the "./" would be trying to spawn a process from the same directory as where you ran python. but, int he mean time, I see in the code that you have set up the paths properly.
However, I was farting around with subprocesses in python yesterday (for another reason). I can start another app without any probs using os.system( ). I had some problems with os.spawnl() calls. I also tried using python's subprocess wrapper, Popen() -> but, that just calls execl(), or spawnl() or system() as it sees fit. Today, I will try to run os.system() in a thread and see if I can get decent behavior. The app I am trying to run is mplayer.
-august.
august(e)k dio:
actually, I think if the Pd-0.38-4-extended-RC1.app is in the same directory where you start python, then you want to try something like this: pdexc = os.path.join(execdir, "./Pd-0.38-4-extended-RC1.app/Contents/Resources/bin/pd")
^ | | -> notice the "./"
hi august
i tried and it doesnt seem to make any difference. Looks like Python doesnt like something about PD.
nico,
sorry, I wrote that email early in the morning. the only reason for doing the "./" would be trying to spawn a process from the same directory as where you ran python. but, int he mean time, I see in the code that you have set up the paths properly.
However, I was farting around with subprocesses in python yesterday (for another reason). I can start another app without any probs using os.system( ). I had some problems with os.spawnl() calls. I also tried using python's subprocess wrapper, Popen() -> but, that just calls execl(), or spawnl() or system() as it sees fit. Today, I will try to run os.system() in a thread and see if I can get decent behavior. The app I am trying to run is mplayer.
-august.
hi
I tried.os.system() and it does open Pd properly but python waits until PD is finished to keep running. I need both Python and PD to work concurrently. Same for os.execl()
This is as far as i got. I use
execdir = os.path.dirname(sys.argv[0]) launcher = os.path.join(execdir, "launcher") os.spawnl(os.P_NOWAIT, launcher, '')
to run a shell script like this: #!/bin/sh ~/Desktop/mypythonapp.app/Contents/Resources/Pd-0.38-4-extended-RC1.app/Contents/MacOS/Pd -nogui ~/Desktop/mypythonapp.app/Contents/Resources/audio.pd
this is pretty close to what i if not because of the startup flags not working. I tried to use os.spawnl to open other apps and it doesnt work either. Maybe the process is somehow under control of Python and doesnt like it? Bob in the apple python list suggested to use Python 2.4's LaunchServices module, but i am running 2.3, or pyObjC but i would like to find a crossplatform solution.
i keep seearching ...
I tried.os.system() and it does open Pd properly but python waits until PD is finished to keep running. I need both Python and PD to work concurrently. Same for os.execl()
This is as far as i got. I use
execdir = os.path.dirname(sys.argv[0]) launcher = os.path.join(execdir, "launcher") os.spawnl(os.P_NOWAIT, launcher, '')
I just got some decent results usint python threading.
try this:
import threading, os import time
class PdTask(threading.Thread): def __init__(self, command): threading.Thread.__init__(self) self.command = command def run(self): os.system(self.command)
exec_command = "/path/to/pd -arg 1 -arg 2" pdthread = PdTask(exec_command) pdthread.start()
while 1: # do all the python stuff you need # we'll just sleep here for testing purposes time.sleep(1)
# optionally you could wait for pd to quit before ending pdthread.join()
nico(e)k dio:
# execdir = os.path.dirname(sys.argv[0]) pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/MacOS/Pd") arg = os.path.join(execdir, "audio.pd") os.spawnl(os.P_NOWAIT, pdexc, arg) # etc ...
try with pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/Contents/Resources/bin/pd")
i have been looking into it better and it looks like pd is kind of open. check attached screenshot. the terminal top command sais there is a process called pd running
look at the two windows open on the left, one is a console and the small one is audio.pd which is the name of the file i am trying to open in pd. Looks like it doesnt fully get opened or something like that.
maybe it would be easier to do a shell script to open both pd and python.
On Sep 1, 2005, at 12:38 PM, altern wrote:
nico(e)k dio:
try with pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/ Contents/Resources/bin/pd")
i have been looking into it better and it looks like pd is kind of
open. check attached screenshot. the terminal top command sais there is a process called pd runninglook at the two windows open on the left, one is a console and the
small one is audio.pd which is the name of the file i am trying to
open in pd. Looks like it doesnt fully get opened or something like
that.maybe it would be easier to do a shell script to open both pd and
python.
...I don't know much about python, but from your screenshot, I can
see a "Pd" process in 'top', but no "pd" process: this has to do
with the version of pd you are trying to use..."Pd" in this case is
just the Wish Shell.app binary under a different name, so you are not
actually opening pd proper...
...my suggestion would be to use a "traditional" or "normal" version
of the command line version of pd, which would at least reduce the
number of variables you're dealing with...get that working, then try
it with the app_pkg version...
l8r, jamie
james tittle(e)k dio:
On Sep 1, 2005, at 12:38 PM, altern wrote:
nico(e)k dio:
try with pdexc = os.path.join(execdir, "/Pd-0.38-4-extended-RC1.app/ Contents/Resources/bin/pd")
i have been looking into it better and it looks like pd is kind of open. check attached screenshot. the terminal top command sais there is a process called pd running
look at the two windows open on the left, one is a console and the
small one is audio.pd which is the name of the file i am trying to
open in pd. Looks like it doesnt fully get opened or something like
that.maybe it would be easier to do a shell script to open both pd and
python....I don't know much about python, but from your screenshot, I can see a "Pd" process in 'top', but no "pd" process: this has to do with the version of pd you are trying to use..."Pd" in this case is just the Wish Shell.app binary under a different name, so you are not actually opening pd proper...
oook, i understand. It is pretty bizarre.
...my suggestion would be to use a "traditional" or "normal" version of the command line version of pd, which would at least reduce the number of variables you're dealing with...get that working, then try it with the app_pkg version...
l8r, jamie
yes this would make it definitely easier but i need to be able to package everything into a directory containing the python modules and libraries, PD and the pd patch. I need to ble able to drag and drop it anywhere and run all just by clicking the main package.
thanks
Hi,
I have a program in python that does graphics and talks to PD via OSC. Up to now i have run manually both the python app and the PD file. BUt now I am trying to launch PD from the python code but i cannot make it work.
you could also try running your graphics program with the py/pyext external in detached mode. best, Thomas