Hi Terry,

> I suppose that I could set up another apscheduler event to do a reboot
> at midnight.

If they don't need to normally twiddle switches after it powers on to
have it carry out the typically desired routines, then yes you could.

> > I doubt leaks would be sufficient to consume all that spare memory.
> > More likely you'd run out of file descriptors or some other resource
> > first, e.g. opening /dev/null each time you play a tune and never
>
> Should I be closing it?  If so, how?

I don't remember the code precisely, but I did suggest not opening
/dev/null each time the function was called, but instead having a global
and only opening it the once.  open() gives a File object and they have
a close() method.

    >>> f = open('/dev/null')
    >>> f
    <open file '/dev/null', mode 'r' at 0x7f7a9e195660>
    >>> f.close()
    >>> f
    <closed file '/dev/null', mode 'r' at 0x7f7a9e195660>

    https://docs.python.org/2/library/functions.html#open
    https://docs.python.org/2/library/stdtypes.html#bltin-file-objects

> > `ls -l /proc/$pid/fd' would show what file descriptors
> > process $pid has open at that moment.
>
> I can't make that do anything:
>
> terry@OptiPlex:~$ ls -l /proc/$pid/fd 

Did you set `pid` to the process ID of interest?  Or replace `$pid' with
that number?  :-)

    $ python2 -c 'import time; f = open("/etc/passwd"); time.sleep(42)' &
    [1] 18933
    $ ls -l /proc/18933/fd
    total 0
    lrwx------ 1 ralph ralph 64 Apr  3 16:36 0 -> /dev/pts/2
    lrwx------ 1 ralph ralph 64 Apr  3 16:36 1 -> /dev/pts/2
    lrwx------ 1 ralph ralph 64 Apr  3 16:36 2 -> /dev/pts/2
    lr-x------ 1 ralph ralph 64 Apr  3 16:36 3 -> /etc/passwd
    $

0, 1, 2 are its stdin, stdout, and stderr.  The lowest available file
descriptor is returned on a successful open(2) so /etc/passwd became 3.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2017-04-04 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue     / TO THE LIST OR THE AUTHOR

Reply via email to