[Twisted-Python] supressess warnings

Christopher Armstrong radix at twistedmatrix.com
Tue Apr 1 14:11:18 EST 2003


On Tue, Apr 01, 2003 at 07:00:53AM -0500, Andrew Dalke wrote:

> A bit of searching later and I found
>   twisted/python/log.py
> which redefines (!) warnings.showwarning to dump the data to a
> logfile, which is initialized to a NullFile(), which does nothing.

Yeah, replacing showwarnings is the idiomatic way to override the
display of warnings. The bit that initializes the default logfile to
NullFile is something moshez and glyph wanted, and, for the record,
something I'm against. (sorry glyph :-)

> I started to change the code, so I could submit a patch.  I got the
> code out of CVS and am reading the documentation at
>   http://twistedmatrix.com/documents/howto/coding-standard
> It says that the main test suite builder is in 'twisted.test.test_all'
> 
> That module doesn't exist (can't import it) nor is the appropriate
> file present anywhere.  And the hyperlink from that page yields
>   "No Such Resource
>    File not found."

Oh, that's a bit out of date. Just run `./bin/trial -p twisted.test'
if you want to run all of the Twisted tests. I'll update the doc.

> It then says
>   Acceptance tests are all automated by the bin/accepttests
> but that program is in admin/accepttests
> 
> I ran that for my Mac OS X machine, with 'open' as the
> WEBBROWSER setting (where does the '-b' option go, since
> open doesn't block .. do I pass it to 'accepttests'?  Yes.) and  
> /bin/true
> as my IRCCLIENT, since I wouldn't know what to do with one
> even assuming I had one.

Note that all developers aren't really expected to run these, it's
super-dependant on your environment and is finicky about how exactly
you start the script. I'll add this to the doc, as well.


...

Oh, it seems itamar just fixed those issues with the coding standard.

> Anyway, after a while it gave this error

> Running Command: './admin/../bin/mktap mail --domain foo.bar=dump  
> --user postmaster=postmaster  --pop 18110'
> option --pop not a unique prefix

I have no idea what this error means.

> Hmmm.... Is 'admin/runtests' the correct script to run?  I ran that,
> and got the following output

Yeah, `admin/runtests' just runs `bin/trial -p twisted.test', for
convenience.

> ======================================================================== 
> FAILURE: testReadLimit (twisted.test.test_policies.ThrottlingTestCase)
> ------------------------------------------------------------------------ 

> ======================================================================== 
> FAILURE: testWriteLimit (twisted.test.test_policies.ThrottlingTestCase)
> ------------------------------------------------------------------------ 

> ======================================================================== 
> FAILURE: testPackages (twisted.test.test_setup.CheckingPackagesTestCase)
> ------------------------------------------------------------------------ 

This happened because you didn't use the `-P' option to cvs
update/checkout. Please put this in your ~/.cvsrc:

"""
update -d -P
checkout -P
"""

> ======================================================================== 
> FAILURE: testFailing (twisted.test.test_tcp.LoopbackTestCase)
> ------------------------------------------------------------------------ 

> ======================================================================== 
> ERROR: testUnicodeTolerance (twisted.test.test_xml.MicroDOMTest)
> ------------------------------------------------------------------------ 


I have no idea what the rest of the problems were about, though.

> And for the life of me I can't figure out why the log file should
> default (when no logging is enabled) to the NullFile rather than
> sys.stderr -- if you really want the NullFile, just pass it in.  So
> I switched it to use sys.stderr.
 
I wish this could be accepted, but unless glyph changes his mind, it
probably won't. The usual response is to use twistd, but twistd isn't
appropriate in all use-cases (it is in yours, however). The *reason*,
IIRC, was that "you shouldn't spam unwanted stuff to STDIO", which I
think is stupid. Application developers could notice spam to stdio,
and, if they don't like it, startLogging to NullFile. (I've heard a
lot more complaints about "Why don't I see any output!?" than "Why
does Twisted write stuff to my stdio?")

</rant>

Sorry, I guess I'll stop beating a dead horse. :)

> Why's the Log pickleable? What happens if a cStringIO is passed
> in instead of a file?  Or an outgoing network socket?  Or a
> os.popen("lp")?

Well, it should probably be pickleable only when it _can_ be. :) i.e.,
__getstate__ could test for a `.name' attribute on the file object, or
something. Handling stuff like StringIO might be a bit trickier
without hardcoding an `isinstance(self.file, StringIO)' into
it... Perhaps it could `try: cPickle.dumps(self.file)' to test if the
file's pickleable in the case where it's not a named file ;-)

> It looks like Log.synchronized is old code that can be removed.  Yes?

No, I'm pretty sure this is so threaded code that writes to the log
doesn't break.

> Why does doc/examples/cursesclient.py set log.logfile directly?
> Shouldn't it call log.startLogging(log.NullFile()) ?  It's the only  
> other
> piece of code which references log.NullFile.

Probably.

> Is 'discardLogs' the true inverse of startLogging?  If so, it
> should add something to restore sys.stdout/sys.stderr if
> startLogging asked them to be changed.
> 
> If not, where's the 'stopLogging' function?  And 'discard'
> means to ignore logging?  Or should it throw away the
> log files?  The terminology is confusing.

Well, if you want to switch your logging to something else
(sys.stdout/stderr), then pass that something else to startLogging,
probably.


> Anyway, the diff -u is attached for you all to review and
> correct. 

> Oh, and with my changes, I now see the expected warning
> when I start up, and I see two twisted messages ...
> 
> [Andrew-Dalkes-Computer:~/cvses/Twisted] dalke% python cansmi_rpc.py
> /usr/local/lib/python2.3/site-packages/openeye/oechem.py:5: 
> RuntimeWarning: Python C API version mismatch for module _oechem: This 
> Python has API version 1012, module _oechem has version 1011.
>   import _oechem
> twisted.web.server.Site starting on 8080
> Starting factory <twisted.web.server.Site instance at 0x640850>
> 
> which tells me that those two messages ("Site starting" and "Starting
> factory") were being sent to never-never-land the whole time.  Perhaps
> the latter shouldn't be present?

Well, no, usually people use twistd. Which you should, if you're
writing a server. It handles logging, daemonization, and a whole slew
of other things for you, and, contrary to what most people think,
doesn't require the use of .taps (see the `-y' parameter).


Anyway, thanks for the in-depth message, it was helpful.

-- 
 Twisted | Christopher Armstrong: International Man of Twistery
  Radix  |          Release Manager,  Twisted Project
---------+     http://twistedmatrix.com/users/radix.twistd/




More information about the Twisted-Python mailing list