0

I am using twisted and python to send some large text file over network, I would like to use UDP and multicast, What solution would be the best to do it, I need sample code cause I am already confused, When I try to do it I get error 24 from python which says too many open files, could you help me to resolve this issue?

here is part of my code:

    if (options.upt != None):
        print "UPGRADE is initiating"
        sourceFile = open(options.upt, "r")
        reactor.listenMulticast(1888, UpgradeReciever("Control Listener"), listenMultiple=True)
        #with open(options.upt) as sourceFile:
        for line in sourceFile:
            upgradeSenderObj = UpgradeSender(line, "224.0.0.8", 1888)
            reactor.listenMulticast(1888, upgradeSenderObj, listenMultiple=True)
        reactor.run()

I have also tried to read the whole file and put in list and then call each element of list (which are in fact lines of my file) by twisted, but still got the similar problem, here is my updated code:

    if (options.upt != None):
        print "UPGRADE is initiating"
        sourceFile = open(options.upt, "r")
        reactor.listenMulticast(1888, UpgradeReciever("Control Listener"), listenMultiple=True)

        dataContainer = list(sourceFile)
        print dataContainer
        for i in range(len(dataContainer)):
            upgradeSenderObj = UpgradeSender(dataContainer[i], "224.0.0.8", 1888)
            reactor.listenMulticast(1888, upgradeSenderObj, listenMultiple=True)
        reactor.run()
DeFoG
  • 215
  • 2
  • 12
  • possible duplicate of [Multicast in Python](http://stackoverflow.com/questions/603852/multicast-in-python) – Robᵩ Sep 03 '14 at 20:05
  • What am I suppose to do in order to fix it? – DeFoG Sep 03 '14 at 20:13
  • You wrote, "I need sample code cause I am already confused." Click on the link in my comment -- you'll find sample code there. – Robᵩ Sep 03 '14 at 20:15
  • thanks for link , but I need twisted sample code, – DeFoG Sep 03 '14 at 20:23
  • The problem was before for loop i was suppose to close a file otherwise with each iterate python links a pointer to separate openfile and finally it gets too many openfiles, the interesting thing here is if just remove twisted lines inside for loop and execute any pure python code in it, it will execute without any error, by twisted code I had too many open files error. – DeFoG Sep 04 '14 at 12:29

0 Answers0