[wxPython-users] parameters functions

Christopher Barker Chris.Barker at noaa.gov
Fri Mar 30 09:33:56 PDT 2007


There are a number of odd things in your code:

> I have two buttons, OnLaunch and OnKill. The OnConnect function is as follows:
> def OnLaunch(self,event):
>        child1 = subprocess.Popen(["./gnome-terminal"],cwd="/usr/bin")
>         t =  child1.pid
>         return t
you've just called return, and thus rest of this code won't run, so 
you'll only child1

>         time.sleep(3)
>         child2 = subprocess.Popen(["./xterm"], cwd="/usr/bin")
>         z = child2.pid
>         return z

> Now on My OnKill function:
> def OnKill(self,event):
>         os.kill(self.OnLaunch('pid'),15)
OnLaunch only takes one parameter: "event", but you're trying to pass it 
  a string: 'pid' what do you expect it to do with it?

Also, you're now calling the OnLaunch when you want to kill the process, 
but that will launch another version of it.

>         os.kill(self.OnLaunch('pid'),15)
Why called twice?

>   I just want to pass the process pid's to kill function so I can kill process. I know in C I could use a pointer to accomplish this. Thanks in advance.

I suspect you want something like this in OnLaunch:

self.Child1pid = child1.pid

then in Onkill:

os.kill.(self.Child1pid, 15)


i.e. store the pids in self somehow. (if you may have a bunch of 
processes, then you'd want some other structure to store them, maybe a 
dict or something.
-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the wxpython-users mailing list