Back to index

moin  1.9.0~rc2
thread_monitor.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - Thread monitor action
00004 
00005     Shows the current traceback of all threads.
00006 
00007     @copyright: 2006 MoinMoin:AlexanderSchremmer
00008     @license: GNU GPL, see COPYING for details.
00009 """
00010 import os, time
00011 from StringIO import StringIO
00012 
00013 from MoinMoin import Page, wikiutil
00014 from MoinMoin.util import thread_monitor
00015 
00016 def execute_fs(pagename, request):
00017     _ = request.getText
00018     # check for superuser
00019     if not request.user.isSuperUser():
00020         request.theme.add_msg(_('You are not allowed to use this action.'), "error")
00021         return Page.Page(request, pagename).send_page()
00022 
00023     if thread_monitor.hook_enabled():
00024         s = StringIO()
00025         thread_monitor.trigger_dump(s)
00026         time.sleep(5) # allow for all threads to dump to request
00027         data = s.getvalue()
00028         timestamp = time.time()
00029         dump_fname = os.path.join(request.cfg.data_dir, "tm_%d.log" % timestamp)
00030         f = file(dump_fname, "w")
00031         f.write(data)
00032         f.close()
00033     else:
00034         dump_fname = "nowhere"
00035 
00036     request.write('<html><body>A dump has been saved to %s.</body></html>' % dump_fname)
00037 
00038 def execute_wiki(pagename, request):
00039     _ = request.getText
00040     # be extra paranoid in dangerous actions
00041     actname = __name__.split('.')[-1]
00042     if not request.user.isSuperUser():
00043         request.theme.add_msg(_('You are not allowed to use this action.'), "error")
00044         return Page.Page(request, pagename).send_page()
00045 
00046     request.theme.send_title("Thread monitor")
00047     request.write('<pre>')
00048 
00049     if not thread_monitor.hook_enabled():
00050         request.write("Hook is not enabled.")
00051     else:
00052         s = StringIO()
00053         thread_monitor.trigger_dump(s)
00054         time.sleep(5) # allow for all threads to dump to request
00055         request.write(wikiutil.escape(s.getvalue()))
00056 
00057     request.write('</pre>')
00058     request.theme.send_footer(pagename)
00059     request.theme.send_closing_html()
00060 
00061 execute = execute_fs
00062