python / cpython

The Python programming language
https://www.python.org
Other
63.68k stars 30.51k forks source link

sys.settrace inheritance #35198

Closed 1af41a4c-c5ec-4789-95e6-64c09c7f7f3c closed 16 years ago

1af41a4c-c5ec-4789-95e6-64c09c7f7f3c commented 23 years ago
BPO 462716

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = created_at = labels = ['type-feature'] title = 'sys.settrace inheritance' updated_at = user = 'https://bugs.python.org/majid' ``` bugs.python.org fields: ```python activity = actor = 'draghuram' assignee = 'none' closed = True closed_date = closer = 'draghuram' components = ['None'] creation = creator = 'majid' dependencies = [] files = [] hgrepos = [] issue_num = 462716 keywords = [] message_count = 2.0 messages = ['61070', '61524'] nosy_count = 2.0 nosy_names = ['majid', 'draghuram'] pr_nums = [] priority = 'normal' resolution = 'rejected' stage = None status = 'closed' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue462716' versions = [] ```

1af41a4c-c5ec-4789-95e6-64c09c7f7f3c commented 23 years ago

I am trying to perform test coverage analysis on Corba servers implemented in Python using omniORB, an excellent open-source Corba ORB from AT&T (formerly Oracle-Olivetti) labs in Cambridge, UK.

I am using for this purpose a modified version of Neil Schemenauer's code_coverage.py module, which works by using sys.settrace to set a profiling function.

Unfortunately, new threads do not inherit the trace function set for the parent thread, which means I am not profiling the actual work that gets done in Corba requests :-(

It would be useful to make an option to inherit sys_tracefunc in PyThreadState_New an option so multi-threaded programs can be traced/debugged more easily. I know Fred Drake is reworking the trace framework to allow profilers written in C, but I am not sure if this will address this issue.

I can work around this problem by patching omniORB or PyThreadState_new to copy and INCREF the trace function every time a new thread is created by the C++ code, but I would much prefer a more general solution that could be contributed back to the standard Python code base. Perhaps what is really needed is the ability to hook Python thread startup.

Yours,

-- Fazal Majid

823ad82f-2e9f-4388-9c64-a3126f202a71 commented 16 years ago

I haven't used settrace() functionality myself but a quick test using latest python shows that trace function set with sys.settrace() is not inherited by newly created threads.

I am closing this as there is no activity for long time.