Re: [asterisk-users] [Linux/Python 2.4.2] Forking Python doesn't work

2008-02-14 Thread Vincent
On Wed, 13 Feb 2008 22:26:16 -0500, Russell Bryant
[EMAIL PROTECTED] wrote:
The arguments to System() are a bit different.  Put it in just like you would 
type at the command line.

System(/tmp/netcid.py 2000 Joe)

That did it :-) Thanks guys.

BTW, for those interested, I didn't have to double-fork:

==
#!/usr/bin/python

import socket,sys,time,os

sys.stdout = open(os.devnull, 'w')
if os.fork():
sys.exit(0)
else:
#Here, send broadcast
==


___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


[asterisk-users] [Linux/Python 2.4.2] Forking Python doesn't work

2008-02-13 Thread Vincent
Hello

When a call comes in, I'd like to fork a Python script that
broadcasts a message so that users see the CID name + number pop up on
their computer screen, and simultaneously ring their phones.

The following script doesn't work as planned: It waits until the
script ends before moving on to the next step, which is Dial():

===
exten = s,1,AGI(netcid.py|${CALLERID(num)}|${CALLERID(name)}) exten
= s,n,Dial(${MYPHONE},5)   
===
# cat netcid.py
#!/usr/bin/python

import socket,sys,time,os

def sendstuff(data):
   s.sendto(data,(ipaddr,portnum))
   return

sys.stdout = open(os.devnull, 'w')
if os.fork():
#BAD? sys.exit(0)   
os._exit(0)
else:
now = time.localtime(time.time())
dateandtime = time.strftime(NaVm/%y NaVM, now)

myarray = []
myarray.append(STAT Rings: 1)
myarray.append(RING)
myarray.append(NAME  + cidname)
myarray.append(TTSN Call from  + cidname)
myarray.append(NMBR  + cidnum)
myarray.append(TYPE K)

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,True)

portnum = 42685
ipaddr = 192.168.0.255

for i in myarray:
sendstuff(i)

#Must pause, and send IDLE for dialog box to close
time.sleep(5)
sendstuff(IDLE  + dateandtime)
===

In another forum, people told me that I should fork twice. Is that
really necessary?
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731

Thank you.


___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] [Linux/Python 2.4.2] Forking Python doesn't work

2008-02-13 Thread Diego Aguirre
Vincent,

try to use System() instead of AGI()

Diego Aguirre
Infodag - Informática
FWD#: 459696
Nikotel#: 99 21 8138-2710
EnumLookup#: +55 21 8138-2710
DUNDi-br#: 21 8138-2710

Vincent escreveu:
 Hello
 
   When a call comes in, I'd like to fork a Python script that
 broadcasts a message so that users see the CID name + number pop up on
 their computer screen, and simultaneously ring their phones.
 
 The following script doesn't work as planned: It waits until the
 script ends before moving on to the next step, which is Dial():
 
 ===
 exten = s,1,AGI(netcid.py|${CALLERID(num)}|${CALLERID(name)}) exten
 = s,n,Dial(${MYPHONE},5)   
 ===
 # cat netcid.py
 #!/usr/bin/python
 
 import socket,sys,time,os
 
 def sendstuff(data):
s.sendto(data,(ipaddr,portnum))
return
 
 sys.stdout = open(os.devnull, 'w')
 if os.fork():
 #BAD? sys.exit(0)   
 os._exit(0)
 else:
 now = time.localtime(time.time())
 dateandtime = time.strftime(NaVm/%y NaVM, now)
 
 myarray = []
 myarray.append(STAT Rings: 1)
 myarray.append(RING)
 myarray.append(NAME  + cidname)
 myarray.append(TTSN Call from  + cidname)
 myarray.append(NMBR  + cidnum)
 myarray.append(TYPE K)
 
 s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
 s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,True)
 
 portnum = 42685
 ipaddr = 192.168.0.255
 
 for i in myarray:
 sendstuff(i)
 
 #Must pause, and send IDLE for dialog box to close
 time.sleep(5)
 sendstuff(IDLE  + dateandtime)
 ===
 
 In another forum, people told me that I should fork twice. Is that
 really necessary?
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731
 
 Thank you.
 
 
 ___
 -- Bandwidth and Colocation Provided by http://www.api-digital.com --
 
 asterisk-users mailing list
 To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
 

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] [Linux/Python 2.4.2] Forking Python doesn't work

2008-02-13 Thread Michiel van Baak
On 13:46, Wed 13 Feb 08, Vincent wrote:
 Hello
 
   When a call comes in, I'd like to fork a Python script that
 broadcasts a message so that users see the CID name + number pop up on
 their computer screen, and simultaneously ring their phones.
 
 The following script doesn't work as planned: It waits until the
 script ends before moving on to the next step, which is Dial():
 
 In another forum, people told me that I should fork twice. Is that
 really necessary?
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731

If you want it to detach the program from it's parent you
need the double fork yes.

-- 

Michiel van Baak
[EMAIL PROTECTED]
http://michiel.vanbaak.eu
GnuPG key: http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x71C946BD

Why is it drug addicts and computer aficionados are both called users?


___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] [Linux/Python 2.4.2] Forking Python doesn't work

2008-02-13 Thread Vincent
On Wed, 13 Feb 2008 10:59:38 -0200, Diego Aguirre
[EMAIL PROTECTED] wrote:
try to use System() instead of AGI()

Thanks, but no go. I get an error:

[Feb 13 21:57:55] WARNING[2138]: app_system.c:107 system_exec_helper:
Unable to execute '/tmp/netcid.py|2000|Joe'


___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] [Linux/Python 2.4.2] Forking Python doesn't work

2008-02-13 Thread Vincent
On Wed, 13 Feb 2008 14:25:52 +0100, Michiel van Baak
[EMAIL PROTECTED] wrote:
If you want it to detach the program from it's parent you
need the double fork yes.

Thanks for the confirmation, but when doing this, the NetCID
application no longer pops up, regardless of whether I put the NetCID
code in the second parent or second child:


exten = 9300,1,AGI(/tmp/test5.py|${CALLERID(num)}|${CALLERID(name)})
exten = 9300,n,Dial(${MYPHONE},15)

# cat test5.py 

#!/usr/bin/python
import socket,sys,time,os

def sendstuff(data):
   s.sendto(data,(ipaddr,portnum))
   return

log = open('/tmp/output.txt','w')

sys.stdout = open(os.devnull, 'w')
if os.fork():
#Parent
log.write(Step 1\n)
log.close()
os._exit(0)
else:
#Child
os.chdir('/tmp')
os.setsid()
os.umask(0)

if os.fork():
#Parent
log.write(Step 2\n)
log.close()

now = time.localtime(time.time())
dateandtime = time.strftime(%d/%m/%Y %H:%M, now)

myarray = []
myarray.append(STAT Rings: 1)
myarray.append(RING)
myarray.append(NAME  + cidname)
myarray.append(TTSN Call from  + cidname)
myarray.append(NMBR  + cidnum)
myarray.append(TYPE K)

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
 s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,True)

portnum = 42685
ipaddr = 192.168.0.255

for i in myarray:
sendstuff(i)

time.sleep(5)
sendstuff(IDLE  + dateandtime)
os._exit(0)
else:
#Child
log.write(Step 3\n)
log.close()
os._exit(0)


Has someone already forked a Python script successfully from Asterisk
through AGI?

Thanks.


___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] [Linux/Python 2.4.2] Forking Python doesn't work

2008-02-13 Thread Russell Bryant
Vincent wrote:
 On Wed, 13 Feb 2008 10:59:38 -0200, Diego Aguirre
 [EMAIL PROTECTED] wrote:
 try to use System() instead of AGI()
 
 Thanks, but no go. I get an error:
 
 [Feb 13 21:57:55] WARNING[2138]: app_system.c:107 system_exec_helper:
 Unable to execute '/tmp/netcid.py|2000|Joe'

The arguments to System() are a bit different.  Put it in just like you would 
type at the command line.

System(/tmp/netcid.py 2000 Joe)

-- 
Russell Bryant
Senior Software Engineer
Open Source Team Lead
Digium, Inc.

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users