コメントにthreadとsubprocessを使ったサンプル。
bug があるらしい。
これと同じとのこと。
SocketServer.ForkingMixIn.collect_children() does:
pid, status = os.waitpid(0, options)
By setting pid = 0, it will wait on any children, even
if the children were not started by the SocketServer.
This causes sporadic test failures:
うは。見つけていたら頭からこのバグに突っ込んでいたかも。
2.5.1にならないとなおらんだと・・・・。いかんなぁ。
解析に使うgnubg重いから、何かforkすることは確定なので。
loggingもせにゃならん。
- hathaway daemonは標準のloggingを使っている。ので、やっぱりloggingをつかう。
- 自前コードはimport logging + logging.debug/infoなどで好きにできる。
- XMLRPCはログをstderrにだす。どっかのパラメータで挙動かえられたっけ?
- コンストラクタの引数になにやら渡せばいい。ブツは何だろう?:SimpleXMLRPCServer(addr[, requestHandler[, logRequests]])
- Booleanぽい。今したいことはstderrに垂れ流す代わりにloggingを使ってほしいのだ。
- SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.log_request(self, code='-', size='-')Selectively log an accepted request.か?実装はこんな感じだ。
def log_request(self, code='-', size='-'):
"""Selectively log an accepted request."""
if self.server.logRequests:
BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size)
- 落とし穴
- Python で logging
logの問題。web.pyのコード。log_messageをオーバーライドしてあげればよいようだ。
def log_message(self, format, *args):
"""Log a message; overrides 'BaseHTTPRequestHandler.log_message'."""
# Write an Apache-style log entry via the server instance.
message = "%s - - [%s] %s\n" \
% (self.address_string(),
self.log_date_time_string(),
format%args)
self.server.LogMessage(message)
元のコード(from BaseHTTPServer.py)
def log_message(self, format, *args):
"""Log an arbitrary message.
This is used by all other logging functions. Override
it if you have specific logging wishes.
The first argument, FORMAT, is a format string for the
message to be logged. If the format string contains
any % escapes requiring parameters, they should be
specified as subsequent arguments (it's just like
printf!).
The client host and current date/time are prefixed to
every message.
"""
sys.stderr.write("%s - - [%s] %s\n" %
(self.address_string(),
self.log_date_time_string(),
format%args))
0 件のコメント:
コメントを投稿