This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: asyncore module print to stdout
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: giampaolo.rodola Nosy List: eric.araujo, giampaolo.rodola, kaplun
Priority: normal Keywords:

Created on 2011-04-07 08:22 by kaplun, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg133198 - (view) Author: Samuele Kaplun (kaplun) Date: 2011-04-07 08:22
The method "log_info" of the "dispatcher" class of the asyncore.py module, uses print statement to print to stdout.

This lead to conflicts when asyncore is used within e.g. mod_wsgi, as writing to stdout is not supposed to be valid.
msg133206 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-04-07 10:11
What change are you proposing exactly?
Btw, overriding log_info() in such cases seems reasonable to me, without changing anything in asyncore.
msg133208 - (view) Author: Samuele Kaplun (kaplun) Date: 2011-04-07 11:33
Thanks for looking into it.

Indeed that's the workaround I implemented in our application. On the other hand it would be nice if either:

* the log_info method would print to stderr,
* would use warning.warn()
* would use the logging module to allow for fine grained configuration

The 1st solution would be already enough for mod_wsgi usage (also see: <http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Writing_To_Standard_Output>)

Cheers!
msg133209 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-04-07 12:01
asyncore is a minimalistic and generic framework; as such it should not "privilege" a specific application such as mod_wsgi or make any other assumption.

I'd say it's fine to let user decide what to do in its own subclass.

Furthermore, log_info() is used by asyncore only to warn about events which are supposed to be handled by user via method overriding (e.g. handle_read()). It's not something you want wsgi or any other application except yours to be aware of.
msg133211 - (view) Author: Samuele Kaplun (kaplun) Date: 2011-04-07 12:23
Hi Giampaolo,

shouldn't then the 2nd option I was proposing (i.e. to call warning.warn) the best behavior, given your explanation?

[...]
Warning messages are typically issued in situations where it is useful to alert the user of some condition in a program, where that condition (normally) doesn’t warrant raising an exception and terminating the program. For example, one might want to issue a warning when a program uses an obsolete module.

Python programmers issue warnings by calling the warn() function defined in this module. (C programmers use PyErr_WarnEx(); see Exception Handling for details).
[...]

In this case asyncore might want raise a warning, since the client code of asyncore was expected to handle the event.

If the semantic of log_info is to basically alert the developer is there any particular benefit in printing directly to stdout rather than raising a warning (or simply printing to stderr)?

Ciao!
msg133325 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-04-08 16:20
Some guidance on print vs. warnings vs. logging on http://docs.python.org/dev/howto/logging#when-to-use-logging
msg220562 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2014-06-14 15:10
Looking back at this: a warning seems a bit too invasive to me as there are cases where avoiding to override a certain methods are legitimate.
I will just close this out as won't fix, also because asyncore has been deprecated by asyncio.
History
Date User Action Args
2022-04-11 14:57:15adminsetgithub: 56001
2014-06-14 15:10:56giampaolo.rodolasetstatus: open -> closed
resolution: wont fix
messages: + msg220562

stage: needs patch ->
2011-06-01 06:31:15terry.reedysetversions: - Python 2.5, Python 3.1
2011-04-08 16:20:28eric.araujosetnosy: + eric.araujo
messages: + msg133325
2011-04-07 12:23:50kaplunsetmessages: + msg133211
2011-04-07 12:01:11giampaolo.rodolasetmessages: + msg133209
2011-04-07 11:33:40kaplunsetmessages: + msg133208
2011-04-07 10:11:32giampaolo.rodolasetmessages: + msg133206
2011-04-07 10:07:37pitrousetassignee: giampaolo.rodola
stage: needs patch

nosy: + giampaolo.rodola
versions: + Python 3.2, Python 3.3, - Python 2.6
2011-04-07 08:22:26kapluncreate