Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'else:': 0.03; 'root': 0.05; 'error:': 0.07; 'modify': 0.07; 'weeks.': 0.07; 'app,': 0.09; 'except:': 0.09; 'method:': 0.09; 'try:': 0.09; 'weeks,': 0.09; 'thread': 0.14; '24]': 0.16; 'e.errno': 0.16; 'files:': 0.16; 'issue?': 0.16; 'threads.': 0.16; 'true:': 0.16; 'prevent': 0.16; 'thanks,': 0.17; 'app': 0.19; 'file,': 0.19; 'written': 0.21; 'python?': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'file.': 0.24; 'correct': 0.29; 'raise': 0.29; 'reaches': 0.30; "i'm": 0.30; 'file': 0.32; 'weeks': 0.32; 'open': 0.33; 'except': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'application': 0.37; 'too': 0.37; 'skip:o 20': 0.38; 'handle': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'ago.': 0.61; 'break': 0.61; 'from:charset:utf-8': 0.61; 'content- disposition:inline': 0.62; 'today': 0.64; 'hours': 0.66; 'here': 0.66; '3-4': 0.68; 'datas': 0.84; 'received:86': 0.91; 'received:hu': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:content-transfer-encoding:user-agent; bh=raTUeLxQ+03BU2IcvSpqiLxvtbmtntSuocAkTfg5N3g=; b=DyUuTG6w7wzBa1F0N9DE+JwMAy3FUKXxYKAQvvFvkZCX4On4/oatiFrlif1WLziNc5 KFaTuEfrTCVIICAQDMXOUGHucFgYiX4PLGjvni1/vW832fi4oFYby7L6R7KaipA4uRBu Rqs7eSRGyCCeBb2DvpgN+mKG90+YJRsEbKIiXpkAfMQ9ZEgBAJtUOb+xH0KFNzjUTq6Q 2sM6+Ka9qGOvVNg0ru3cWiYvddRYsjd6uCgVUS8zmFELZndSNFeYlxjQIG30kay/M/SK 5+ryZ4iNLYGIRK4IfRbCgpeZgJDns5Eqpk7o9Oge8n6usXorWQeTfOt0IwIh07VER2CZ nsQA== X-Received: by 10.180.98.98 with SMTP id eh2mr6134132wib.31.1427813376094; Tue, 31 Mar 2015 07:49:36 -0700 (PDT) Date: Tue, 31 Mar 2015 16:50:12 +0200 From: Ervin =?utf-8?Q?Heged=C3=BCs?= To: python-list@python.org Subject: Lockfile hanling MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427813384 news.xs4all.nl 2957 [2001:888:2000:d::a6]:59224 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88385 Hello, there is an app, written in Python, which stores few bytes of datas in a single file. The application uses threads. Every thread can modify the file, but only one at a time. I'm using a lock file to prevent the multiple access. Here is the lock method: while True: try: fl = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR) except OSError, e: if e.errno != errno.EEXIST: raise time.sleep(0.2) continue except: syslog.syslog(syslog.LOG_DEBUG, "Sync error: " + str(sys.exc_info()[1])) else: break This works as well for me - about 3-4 weeks. After some weeks, I got this error: OSError: [Errno 24] Too many open files: '/var/spool/myapp/queue.lock' Today the app had been restarted, about 3-4 hours ago. Now I see under the proc/PID/fd: lrwx------ 1 root root 64 márc 31 16.45 5 -> /var/spool/myapp/queue.lock (deleted) there are about 50 deleted FD's. After few weeks the process reaches the number if max fd's. How can I prevent or avoid this issue? What's the correct way to handle the lockfile in Python? Thanks, Ervin