Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25985
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ivdneut@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'startup': 0.05; 'except:': 0.07; 'exception.': 0.07; 'executed': 0.07; 'skip:/ 10': 0.07; 'stops': 0.07; 'try:': 0.07; 'utf-8': 0.07; 'python': 0.09; 'exception:': 0.09; 'nameerror:': 0.09; 'object)': 0.09; 'os.close(fd)': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'ignore': 0.13; '--version': 0.16; '24,': 0.16; 'code?': 0.16; 'descriptors': 0.16; 'descriptors,': 0.16; 'process?': 0.16; 'range(0,': 0.16; 'sys.exit(0)': 0.16; 'string': 0.17; 'wrote:': 0.17; 'directory.': 0.17; 'working.': 0.17; 'creates': 0.18; 'suddenly': 0.22; 'defined': 0.22; 'runs': 0.22; 'installation': 0.23; 'programming': 0.23; '>': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:2**1': 0.24; 'linux': 0.24; 'script': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; '(most': 0.27; 'cc:addr:gmail.com': 0.27; 'object,': 0.27; "doesn't": 0.28; 'skip:( 20': 0.28; 'run': 0.28; '-0700,': 0.29; 'cat': 0.29; 'parent': 0.29; 'routine': 0.29; 'str': 0.29; 'code': 0.31; 'point': 0.31; 'file': 0.32; 'running': 0.32; 'could': 0.32; 'getting': 0.33; 'doubt': 0.33; 'traceback': 0.33; 'skip:& 20': 0.33; 'version': 0.34; 'received:google.com': 0.34; 'loss': 0.34; 'done': 0.34; 'server': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'child': 0.36; 'stock': 0.36; 'problems': 0.36; 'skip:p 20': 0.36; 'ones': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'received:209.85.214': 0.39; 'release': 0.39; 'hello,': 0.39; 'your': 0.60; 'july': 0.60; 'red': 0.60; 'first': 0.61; 'email addr:gmail.com': 0.63; 'jul': 0.65; 'home': 0.66; 'open,': 0.84; 'received:209.85.214.184': 0.84; 'received :mail-ob0-f184.google.com': 0.84; 'drops': 0.91; 'online,': 0.98 |
| Newsgroups | comp.lang.python |
| Date | Tue, 24 Jul 2012 05:41:22 -0700 (PDT) |
| In-Reply-To | <mailman.2531.1343132808.4697.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=145.23.254.101; posting-account=W0yZ_goAAADAYkC_Qnpsg0MUvOyZ5Sm4 |
| References | <bfa7b7ac-d288-4889-8e48-dd0ff0cad711@googlegroups.com> <mailman.2531.1343132808.4697.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 145.23.254.101 |
| MIME-Version | 1.0 |
| Subject | Re: Daemon loses __file__ reference after a while. |
| From | "ivdneut@gmail.com" <ivdneut@gmail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org, "ivdneut@gmail.com" <ivdneut@gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.2534.1343133685.4697.python-list@python.org> (permalink) |
| Lines | 130 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1343133685 news.xs4all.nl 6900 [2001:888:2000:d::a6]:35916 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:25985 |
Show key headers only | View raw
On Tuesday, July 24, 2012 2:24:31 PM UTC+2, Ervin Hegedüs wrote:
> hello,
>
> On Tue, Jul 24, 2012 at 04:48:42AM -0700, ivdneut@gmail.com wrote:
> > Hello,
> >
> > I have a daemon process that runs for a considerable amount of time (weeks on end) without any problems. At some point I start getting the exception:
> >
> > Exception info: Traceback (most recent call last):
> > File "scheduler.py", line 376, in applyrule
> > result = execrule(rule_code)
> > File "scheduler.py", line 521, in execrule
> > rulepath = os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
> > NameError: name '__file__' is not defined
> >
> > This section of the code is executed in this process *all the time*, but suddenly stops working. I have been searching for similar issues online, but only come accross people having problems because they run the script interactively. This is not the case here.
>
> could you send the relevant part of the code?
>
> I mean: how do you daemonize your process?
It's done by a double fork:
## First fork()
pid = os.fork()
if pid != 0: sys.exit(0) # parent exits.
## create new session
os.setsid()
## ignore SIGHUP
signal.signal(signal.SIGHUP, signal.SIG_IGN)
## Second fork()
pid = os.fork()
if pid != 0: sys.exit(0) # First child exits.
## Change working directory to the home directory.
homedir = pwd.getpwuid(os.geteuid())[5]
os.chdir(homedir)
os.umask(0)
for fd in range(0, 1024):
try:
os.close(fd)
except:
pass # fd not open, ignore this exception.
The original C version of this code is from W.R. Stevens' daemon_init() routine in "UNIX Network Programming Volume 1, second edition"
>
> > I am running python from a virtual-env installation from a stock Red Hat EL 6.2 installation:
> >
> > (virtual-env)[user@host ~]$ python --version
> > Python 2.6.6
> > (virtual-env)[user@host ~]$ cat /etc/redhat-release
> > Red Hat Enterprise Linux Server release 6.2 (Santiago)
>
> If you use fork(), it drops all file descriptors, and creates new
> ones - may be then loss the __file__...?
I doubt this would be it, or it would stop working immediately, since daemonization is done upon startup of the process. File descriptors are closed immediately upon startup, it doesn't seem to affect the reference to the __file__ string (which is not a file object, but a str object)
>
>
> a.
>
>
> --
> I � UTF-8
On Tuesday, July 24, 2012 2:24:31 PM UTC+2, Ervin Hegedüs wrote:
> hello,
>
> On Tue, Jul 24, 2012 at 04:48:42AM -0700, ivdneut@gmail.com wrote:
> > Hello,
> >
> > I have a daemon process that runs for a considerable amount of time (weeks on end) without any problems. At some point I start getting the exception:
> >
> > Exception info: Traceback (most recent call last):
> > File "scheduler.py", line 376, in applyrule
> > result = execrule(rule_code)
> > File "scheduler.py", line 521, in execrule
> > rulepath = os.path.dirname(__file__)+"/"+'/'.join(rule['modules'])+"/"+rule['rulename']
> > NameError: name '__file__' is not defined
> >
> > This section of the code is executed in this process *all the time*, but suddenly stops working. I have been searching for similar issues online, but only come accross people having problems because they run the script interactively. This is not the case here.
>
> could you send the relevant part of the code?
>
> I mean: how do you daemonize your process?
>
> > I am running python from a virtual-env installation from a stock Red Hat EL 6.2 installation:
> >
> > (virtual-env)[user@host ~]$ python --version
> > Python 2.6.6
> > (virtual-env)[user@host ~]$ cat /etc/redhat-release
> > Red Hat Enterprise Linux Server release 6.2 (Santiago)
>
> If you use fork(), it drops all file descriptors, and creates new
> ones - may be then loss the __file__...?
>
>
> a.
>
>
> --
> I � UTF-8
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Daemon loses __file__ reference after a while. "ivdneut@gmail.com" <ivdneut@gmail.com> - 2012-07-24 04:48 -0700
Re: Daemon loses __file__ reference after a while. Ervin Hegedüs <airween@gmail.com> - 2012-07-24 14:24 +0200
Re: Daemon loses __file__ reference after a while. "ivdneut@gmail.com" <ivdneut@gmail.com> - 2012-07-24 05:41 -0700
Re: Daemon loses __file__ reference after a while. "ivdneut@gmail.com" <ivdneut@gmail.com> - 2012-07-24 05:41 -0700
Re: Daemon loses __file__ reference after a while. Laszlo Nagy <gandalf@shopzeus.com> - 2012-07-24 14:31 +0200
Re: Daemon loses __file__ reference after a while. Dieter Maurer <dieter@handshake.de> - 2012-07-24 16:59 +0200
Re: Daemon loses __file__ reference after a while. Paul Rubin <no.email@nospam.invalid> - 2012-07-24 12:32 -0700
Re: Daemon loses __file__ reference after a while. Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-24 14:08 -0600
Re: Daemon loses __file__ reference after a while. Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-24 14:02 -0600
csiph-web