Not forking?
Gilles Ganault
nospam at nospam.com
Thu Nov 22 19:22:10 EST 2007
Hello
I'd like to rewrite the following Perl script in Python:
http://www.voip-info.org/wiki/view/Asterisk+NetCID
It seems like the following doesn't actually fork, so Asterisk is
stuck until the script ends:
===========
import socket,sys,time,os
def sendstuff(data):
s.sendto(data,(ipaddr,portnum))
return
#BAD?
#import posix
#posix.close(1)
#posix.open("/dev/null", posix.O_WRONLY)
#BAD?
sys.stdout = open(os.devnull, 'w')
if os.fork():
sys.exit(0)
try:
cidnum = sys.argv[1]
except:
print "Format: netcid.py cidnum cidname"
sys.exit(1)
try:
cidname = sys.argv[2]
except:
print "Format: netcid.py cidnum cidname"
sys.exit(1)
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"
ipaddr = "localhost"
for i in myarray:
sendstuff(i)
#Must pause, and send IDLE for dialog box to close and call to be
logged in
time.sleep(5)
sendstuff("IDLE " + dateandtime)
===========
What's the correct way to handle this?
Thank you.
More information about the Python-list
mailing list