我使用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()