I think I'm doing something wrong in one of my python scripts

  • Posted:
  • Proposals: 0
  • Remote
  • #668183
  • Expired
  • 0


Experience Level: Intermediate
Hey Ignas,

in one of my projects I'm using Python in combination with Freeswitch. It has been running smoothly for a long time (freeswitch + python that is), but recently I get some coredumps of Freeswitch, which point out it's somethng coming from python, and I sometimes see python struggling to reach my mysql. I think my code can use some revamping, especially the way I connect towards the db, I think I'm doing it all wrong. I think I keep the mysql connection open, which makes things go boom after a while. Perhaps I'ld need to use a sql connection pool?

A code snippet would be:

import datetime
import os
import re
from freeswitch import *

import sys
f = open("myfile.log", "w")
sys.stderr = f
import time
import oursql

conn = oursql.connect(host='localhost',

def retrieve_IVR(extension, groupid):
query = "select ivr from extension left join ivr on ivr.ivr_id=extension.ivr_id where extension.group_id='%s' and extension.extension='%s'" % (groupid, extension)
consoleLog("info", query)
cursor = conn.cursor(oursql.DictCursor)
consoleLog("info", str(ivr))
#if ivr.__len__() == 0:
if ivr == None:
return False
return ivr['ivr'].split(';')

def handler(session, args):

cursor = conn.cursor(oursql.DictCursor)
cursor.execute("select accountid,groupid,callerid from subscriber where username='%s'" % session.getVariable("sip_from_user"))
groupid= result[0]['groupid']
ivr=retrieve_IVR(extension, groupid)

What I'm looking for is someone who clearly is a better programmer than me, reviews the way I approach the db + gives me suggestions on how to do that better.

Perhaps in 2-4 hours you could point me in a better direction?

Kind regards,

New Proposal

Create an account now and send a proposal now to get this job.

Sign up

Clarification Board Ask a Question

    There are no clarification messages.