GLibERROR**:无法创建管道主循环唤醒:打开的文件太多

2024-05-15 05:30:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python的多处理库并行运行两个函数。代码从文件中读取数据,将数据插入数据库,并将任何错误记录到错误文件中。这个程序正在无限期运行。在第一个循环之后,我得到一个错误:GLib-ERROR **: Cannot create pipe main loop wake-up: Too many open files。我不知道这是从哪里来的,因为我确保在使用后打开和关闭文件。下面是一些示例代码

     class DataProcessing:
          def __init___(configlog,sleeptime,logfile):
              self.configlog = configlog
              self.sleeptime = sleeptime
              self.logfile = logfile
              self.manageClient()
              self.setupDB()

          def manageClient(self):
              s=subprocess.Popen([run streaming software])
              time.sleep(self.sleeptime)
              s.kill()
              del s
              self.stream = []
              with open(self.logfile) as f:
                   for line in f.readLines():
                        if "Data" in line:
                             self.stream.append(line)
          def setupDB(self):
              """"Set up connection to database using MySQLdb library"""

          def pushData(self):
              errorfile = open("errorlog.log","a")
               for line in self.stream:
                   """Check of for existing stream in DB. Update record in DB"""
                   try:
                       cur.execute(sql_query) 
                       db.commit()
                   except MySQLdb, e:
                        errorfile.write(e + "\n")
                        db.rollback()
                errorfile.close()
                cur.close()
                db.close()

     def firstProcess():
         while True:
             initialProcess = DataProcessing("configlog",300,"logfile.log")
             initialProcess.pushData()
     def secondProcess():
          while True:
              finalProcess = DataProcessing("otherlog",86000,"otherlog.log")
              finalProcess.pushData()

     p1 = Process(target = firstProcess)
     p1.start()
     p2 = Process(target = secondProcess)
     p2.start()

Tags: inselflogforstreamdef错误line

热门问题