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: trace module doesn't work without threads
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: belopolsky, pitrou, skrah
Priority: normal Keywords: patch

Created on 2010-11-05 20:21 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue10330.diff belopolsky, 2010-11-05 23:32
issue10330-2.diff skrah, 2011-05-25 23:58
Messages (7)
msg120529 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-11-05 20:21
The trace module doesn't work when threading is disabled ("./configure --without-threads"). The following patch fixes this:

diff -r 345827dcf409 Lib/trace.py
--- a/Lib/trace.py      Fri Nov 05 20:58:28 2010 +0100
+++ b/Lib/trace.py      Fri Nov 05 21:20:09 2010 +0100
@@ -53,7 +53,10 @@ import linecache
 import os
 import re
 import sys
-import threading
+try:
+    import threading
+except ImportError:
+    import dummy_threading as threading
 import time
 import token
 import tokenize
msg120556 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-11-05 23:08
I wish I could test this patch but on OSX I get

$ ./configure --without-threads
$ make
Traceback (most recent call last):
  File "/Users/sasha/Work/python-svn/py3k/Lib/site.py", line 519, in <module>
    main()
  File "/Users/sasha/Work/python-svn/py3k/Lib/site.py", line 507, in main
    known_paths = addusersitepackages(known_paths)
  File "/Users/sasha/Work/python-svn/py3k/Lib/site.py", line 253, in addusersitepackages
    user_site = getusersitepackages()
  File "/Users/sasha/Work/python-svn/py3k/Lib/site.py", line 228, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/Users/sasha/Work/python-svn/py3k/Lib/site.py", line 218, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/Users/sasha/Work/python-svn/py3k/Lib/sysconfig.py", line 580, in get_config_var
    return get_config_vars().get(name)
  File "/Users/sasha/Work/python-svn/py3k/Lib/sysconfig.py", line 458, in get_config_vars
    import re
  File "/Users/sasha/Work/python-svn/py3k/Lib/re.py", line 121, in <module>
    import functools
  File "/Users/sasha/Work/python-svn/py3k/Lib/functools.py", line 15, in <module>
    from collections import OrderedDict
  File "/Users/sasha/Work/python-svn/py3k/Lib/collections.py", line 16, in <module>
    from reprlib import recursive_repr as _recursive_repr
  File "/Users/sasha/Work/python-svn/py3k/Lib/reprlib.py", line 8, in <module>
    from _thread import get_ident
ImportError: No module named _thread
msg120559 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-11-05 23:32
dummy_threading feels a bit like black magic to me.  What do you think about something like issue10330.diff attached.
msg120560 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-11-05 23:35
> dummy_threading feels a bit like black magic to me.  What do you think
> about something like issue10330.diff attached.

It's fine for me.
msg120568 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-11-06 01:18
I'll commit tonight.  BTW, on a without-threads build:


>>> import dummy_threading
>>> dummy_threading.settrace
>>> dummy_threading.settrace.__module__
'threading'

In other words, dummy_threading.settrace is always the same as threading.settrace. Since threading.settrace just sets a global variable which is probably not used by dummy_threading, OP's patch is probably fine, but may not be as future proof.
msg120570 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-11-06 01:39
Committed in r86229, merged in r86231 (3.1) and r86233 (2.7).
msg136921 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-05-25 23:58
test_trace still fails on 2.7 on the no-threads bot:

http://www.python.org/dev/buildbot/all/builders/AMD64%20Fedora%20without%20threads%202.7/builds/22/steps/test/logs/stdio


Could you have a short look at the patch. I think it should be correct;
the tests pass.
History
Date User Action Args
2022-04-11 14:57:08adminsetgithub: 54539
2011-05-25 23:58:35skrahsetfiles: + issue10330-2.diff
nosy: + skrah
messages: + msg136921

2010-11-06 01:39:42belopolskysetstatus: open -> closed

messages: + msg120570
stage: commit review -> resolved
2010-11-06 01:18:32belopolskysetresolution: accepted
messages: + msg120568
stage: patch review -> commit review
2010-11-05 23:35:20pitrousetmessages: + msg120560
2010-11-05 23:32:04belopolskysetfiles: + issue10330.diff
keywords: + patch
messages: + msg120559
2010-11-05 23:08:06belopolskysetmessages: + msg120556
2010-11-05 20:21:11pitroucreate