[Python-bugs-list] [Bug #131540] threads and profiler don't work together

noreply@sourceforge.net noreply@sourceforge.net
Fri, 09 Feb 2001 15:57:31 -0800


Bug #131540, was updated on 2001-Feb-08 07:53
Here is a current snapshot of the bug.

Project: Python
Category: Threads
Status: Open
Resolution: None
Bug Group: None
Priority: 3
Submitted by: dbrueck
Assigned to : tim_one
Summary: threads and profiler don't work together

Details: When a new thread is created, it doesn't inherit from the parent
thread the trace and profile functions (sys_tracefunc and sys_profilefunc
in PyThreadState), so multithreaded programs can't easily be profiled. 

This may be by design for safety/complexity sake, but the profiler module
should still find some way to function correctly. A temporary (and
performance-killing) workaround is to modify the standard profiler to hook
into threads to start a new profiler for each new thread, and then merge
the stats from a child thread into the parent's when the child thread
ends.

Here is sample code that exhibits the problem. Stats are printed only for
the main thread because the child thread has no profiling function and
therefore collects no stats:

import threading, profile, time

def yo():
    for j in range(5):
        print j,

def go():
    threading.Thread(target=yo).start()
    time.sleep(1)

profile.run('go()')


Follow-Ups:

Date: 2001-Feb-09 15:57
By: tim_one

Comment:
Assigned to me but reduced the priority.  I'll take a look at it, but have
to suspect it will get reclassified as a Feature Request and moved into PEP
42.
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=131540&group_id=5470