Dr. Dobb's Python-URL! - weekly Python news and links (Jan 13)

Erik Max Francis max at alcyone.com
Mon Jan 13 13:37:03 CET 2003




>From db3l at fitlinxx.com Mon Jan  6 14:45:55 EST 2003
"Simon Bunker" <simon at rendermania.com> writes:

> by RAM usage I mean total free memory - eg what free gives you under Linux.
> Unix/Linux isn't really the problem, but Windows is as I don't know any
> win32 programming.

As others have pointed out, there are a lot of variables in terms of
just what you want to report in terms of memory usage.  But if you
want values that are basically what the Windows Task Manager (at least
under NT/2K/XP - but the API is documented for the 9x series too)
reports, you can use the GlobalMemoryStatus Win32 API function (see
MSDN for the API definition).  I believe it still remains unwrapped by
the win32all package, but here's some example code accessing it with
the available calldll module.  I'm sure you could also use you can
access it with the available ctypes module (and perhaps more simply),
but that didn't exist when I originally wrote this code.

          - - - - - - - - - - - - - - - - - - - - - - - - -
    import calldll, struct

    result   = {}
    kernel32 = calldll.load_library('kernel32')
    memstat  = calldll.get_proc_address(kernel32,'GlobalMemoryStatus')
    if memstat:
        buf = calldll.membuf(32)
        buf.write(struct.pack('1L',32))
        calldll.call_foreign_function(memstat,'l','',(buf.address(),))
        rtuple = struct.unpack('8L',buf.read())
        result['MemoryLoad']    = rtuple[1]   # [0] is len
        result['TotalPhys']     = rtuple[2]
        result['AvailPhys']     = rtuple[3]
        result['TotalPageFile'] = rtuple[4]
        result['AvailPageFile'] = rtuple[5]
        result['TotalVirtual']  = rtuple[6]
        result['AvailVirtual']  = rtuple[7]
    return result
          - - - - - - - - - - - - - - - - - - - - - - - - -

The memory load is in percentage - the other values are all bytes.
This API may not be accurate with more than 2GB of memory in a machine
(it rounds some values down to 2GB) and it will overflow at 4GB -
there's a GlobalMemoryStatusEx call that uses 64-bit return values if
you are worried about such cases, but that's unsupported on the Win 9x
series.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/







        http://artemis.ucsc-extension.edu/~wesc/013e44cd.htm





QOTW:  "Explicit is better than implicit ... especially if you have a
syntax-colouring text editor which highlights 'self' and 'this' ;)"
Tim Delaney

"They added object orientation to Perl?"  Nick Vargish

"I had a manager once who insisted that strict.pm [as in `use strict'
from Perl] was useless 'because it breaks all my programs.'"  Andrew Lee


Announcements
    Guido van Rossum warns of security problems found in rexec and
    Bastion starting with version 2.2; they will be disabled in the
    next 2.3 alpha release and users are actively discouraged from
    using them immediately:
        http://groups.google.com/groups?selm=mailman.1041875417.12807.clpa-moderators%40python.org


Discussion
    David Bolen exemplifies use of calldll for the specific problem
    of reporting memory usage.
	http://groups.google.com/groups?selm=u8yxydzw1.fsf%40fitlinxx.com

    A question about old-style errors involving Unicode strings
    instead of normal strings leads to a discussion about general
    "widening" issues (and the deprecation of raising strings):
        http://groups.google.com/groups?threadm=3e1d5c7b%241%40news.fhg.de

    Martin v. Loewis answers the question of when .pth files are
    needed:
        http://groups.google.com/groups?selm=avh9ql%245lk%2406%241%40news.t-online.com

    Mininal Python is a forming discussion group intent on creating a
    version of Python with a very small C core and most of the rest
    reimplemented in Python itself, including parts of the Python VM,
    suggesting possibilities for runtime/JIT optimization and
    implementations in restricted environments:
        http://groups.google.com/groups?threadm=mailman.1042398202.16333.python-list%40python.org
	http://codespeak.net/mailman/listinfo/pypy-dev

    Is it okay to use something other than `self' for the name of the
    self method argument?  See what Pythonistas think:
        http://groups.google.com/groups?threadm=3E210503.9A4F4AC8%40alcyone.com


Software
    zxSet and zxDateTime are Java/Jython implementations of the
    popular CPython sets (in the upcoming 2.3 release) and DateTime
    modules:
        http://sourceforge.net/projects/zxpy/

    Strip-o-Gram, an HTML conversion library, reaches 1.4 and includes
    Zope support:
        http://www.zope.org/Members/chrisw/StripOGram

    WebWare is a Python-oriented suite of software components for
    developing Web-based applications:
        http://webware.sourceforge.net/

    PAGE, at version 2.2b, is an automatic GUI generator for Python,
    which bears a resemblance to Visual Basic:
        http://page.sourceforge.net/

    Oak DNS Server is a Domain Name Server written in pure Python:
        http://www.digitallumber.com/oak

    PyGeo is a dynamic geometry laboratory requiring VPython:
        http://home.netcom.com/~ajs/    

    Zope reaches 2.6.0:
        http://www.zope.org/


Resources
    Patrick K. O'Brien has written a Python and DB2 tutorial (free
    registration required):
        https://www6.software.ibm.com/reg/devworks/dw-db2pylnx-i?S_TACT=102B7W91&S_CMP=DB2DD

    The Python 2.3 alpha development documentation has been updated
    again, including the updated optparse module documentation:
        http://www.python.org/dev/doc/devel/

    Holger Krekel, putting his money where is mouth is, implements a
    prototype "indendent execution protocol" for Python 2.2.2,
    allowing in effect implicit try-except-else-finally clauses around
    arbitrary blocks by constructing managing objects:
        http://codespeak.net/moin/moin.cgi/IndentedExecution

    Uche Ogbuji writes "Generating DOM Magic" for O'Reilly's xml.com,
    covering using generators in conjunction with XML DOM processing:
        http://www.xml.com/pub/a/2003/01/08/py-xml.html

    Michele Simionato has written an article outlining the new Python
    2.3 method resolution order (MRO):
        http://www.phyast.pitt.edu/~micheles/mro.html


Meetings and Calls For Papers
    Wesley Shun teaches a Python course in the Bay Area.
	http://artemis.ucsc-extension.edu/~wesc/013e44cd.htm

    The Sydney, Australia Python Interest Group is holding its
    January meeting a week early, on January 13 at 7:00 pm at the
    University of Technology Sydney:
        http://groups.google.com/groups?selm=mailman.1041873820.14410.clpa-moderators%40python.org

    The deadline for PyCon 2003 is looming; the submission deadline
    is January 2003, the final versions are due March 10:
        http://www.python.org/pycon/cfp.html

    Alan Runyan is the speaker of the month in the Third Austin Python
    Users Group Meeting:
        http://groups.google.com/groups?selm=mailman.1042235104.18359.clpa-moderators%40python.org


========================================================================

Everything you want is probably one or two clicks away in these pages:

    Python.org's Python Language Website is the traditional
    center of Pythonia
        http://www.python.org
    Notice especially the master FAQ
        http://www.python.org/doc/FAQ.html

    PythonWare complements the digest you're reading with the
    daily python url
         http://www.pythonware.com/daily  
    Mygale is a news-gathering webcrawler that specializes in (new)
    World-Wide Web articles related to Python.
         http://www.awaretek.com/nowak/mygale.html 
    While cosmetically similar, Mygale and the Daily Python-URL
    are utterly different in their technologies and generally in
    their results.

    comp.lang.python.announce announces new Python software.  Be
    sure to scan this newly-revitalized newsgroup at least weekly.
        http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

    Brett Cannon continues the marvelous tradition established by 
    Andrew Kuchling and Michael Hudson of summarizing action on the
    python-dev mailing list once every other week.
	http://www.python.org/dev/summary/
    Partial archives are at
        http://starship.python.net/crew/mwh/summaries/
        http://www.amk.ca/python/dev

    The Vaults of Parnassus ambitiously collect Python resources
        http://www.vex.net/~x/parnassus/   

    Much of Python's real work takes place on Special-Interest Group
    mailing lists
        http://www.python.org/sigs/

    The Python Business Forum "further[s] the interests of companies
    that base their business on ... Python."
	http://www.python-in-business.org

    The Python Software Foundation has replaced the Python Consortium
    as an independent nexus of activity
        http://www.python.org/psf/

    Cetus does much of the same
        http://www.cetus-links.org/oo_python.html

    Python FAQTS
        http://python.faqts.com/

    The old Python "To-Do List" now lives principally in a
    SourceForge reincarnation.
        http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse
        http://python.sourceforge.net/peps/pep-0042.html
     
    The online Python Journal is posted at pythonjournal.cognizor.com.
    editor at pythonjournal.com and editor at pythonjournal.cognizor.com
    welcome submission of material that helps people's understanding
    of Python use, and offer Web presentation of your work.

    *Py: the Journal of the Python Language*
        http://www.pyzine.com

    Tenth International Python Conference 
        http://www.python10.org            

    Archive probing tricks of the trade:
        http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100
        http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.*

Previous - (U)se the (R)esource, (L)uke! - messages are listed here:
  http://www.ddj.com/topics/pythonurl/         
  http://purl.org/thecliff/python/url.html (dormant)
or
  http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python


Suggestions/corrections for next week's posting are always welcome.
E-mail to <Python-URL at phaseit.net> should get through.

To receive a new issue of this posting in e-mail each Monday morning
(approximately), ask <claird at phaseit.net> to subscribe.  Mention
"Python-URL!".


-- The Python-URL! Team--

Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and
sponsor the "Python-URL!" project.





More information about the Python-list mailing list