Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cf428aee
Commit
cf428aee
authored
Sep 21, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #22423: Unhandled exception in thread no longer causes unhandled
AttributeError when sys.stderr is None.
parent
72491090
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
4 deletions
+87
-4
Lib/test/test_threading.py
Lib/test/test_threading.py
+79
-0
Lib/threading.py
Lib/threading.py
+4
-4
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/test/test_threading.py
View file @
cf428aee
...
...
@@ -829,6 +829,85 @@ class ThreadingExceptionTests(BaseTestCase):
thread
.
start
()
self
.
assertRaises
(
RuntimeError
,
setattr
,
thread
,
"daemon"
,
True
)
def
test_print_exception
(
self
):
script
=
r"""if 1:
import threading
import time
running = False
def run():
global running
running = True
while running:
time.sleep(0.01)
1/0
t = threading.Thread(target=run)
t.start()
while not running:
time.sleep(0.01)
running = False
t.join()
"""
rc
,
out
,
err
=
assert_python_ok
(
"-c"
,
script
)
self
.
assertEqual
(
out
,
''
)
self
.
assertIn
(
"Exception in thread"
,
err
)
self
.
assertIn
(
"Traceback (most recent call last):"
,
err
)
self
.
assertIn
(
"ZeroDivisionError"
,
err
)
self
.
assertNotIn
(
"Unhandled exception"
,
err
)
def
test_print_exception_stderr_is_none_1
(
self
):
script
=
r"""if 1:
import sys
import threading
import time
running = False
def run():
global running
running = True
while running:
time.sleep(0.01)
1/0
t = threading.Thread(target=run)
t.start()
while not running:
time.sleep(0.01)
sys.stderr = None
running = False
t.join()
"""
rc
,
out
,
err
=
assert_python_ok
(
"-c"
,
script
)
self
.
assertEqual
(
out
,
''
)
self
.
assertIn
(
"Exception in thread"
,
err
)
self
.
assertIn
(
"Traceback (most recent call last):"
,
err
)
self
.
assertIn
(
"ZeroDivisionError"
,
err
)
self
.
assertNotIn
(
"Unhandled exception"
,
err
)
def
test_print_exception_stderr_is_none_2
(
self
):
script
=
r"""if 1:
import sys
import threading
import time
running = False
def run():
global running
running = True
while running:
time.sleep(0.01)
1/0
sys.stderr = None
t = threading.Thread(target=run)
t.start()
while not running:
time.sleep(0.01)
running = False
t.join()
"""
rc
,
out
,
err
=
assert_python_ok
(
"-c"
,
script
)
self
.
assertEqual
(
out
,
''
)
self
.
assertNotIn
(
"Unhandled exception"
,
err
)
class
LockTests
(
lock_tests
.
LockTests
):
locktype
=
staticmethod
(
threading
.
Lock
)
...
...
Lib/threading.py
View file @
cf428aee
...
...
@@ -818,10 +818,10 @@ class Thread(_Verbose):
# shutdown) use self.__stderr. Otherwise still use sys (as in
# _sys) in case sys.stderr was redefined since the creation of
# self.
if
_sys
:
_sys
.
stderr
.
write
(
"Exception in thread %s:
\
n
%s
\
n
"
%
(
self
.
name
,
_format_exc
()))
el
s
e
:
if
_sys
and
_sys
.
stderr
is
not
None
:
print
>>
_sys
.
stderr
,
(
"Exception in thread %s:
\
n
%s
"
%
(
self
.
name
,
_format_exc
()))
el
if
self
.
__stderr
is
not
Non
e
:
# Do the best job possible w/o a huge amt. of code to
# approximate a traceback (code ideas from
# Lib/traceback.py)
...
...
Misc/NEWS
View file @
cf428aee
...
...
@@ -21,6 +21,10 @@ Core and Builtins
Library
-------
-
Issue
#
22423
:
Unhandled
exception
in
thread
no
longer
causes
unhandled
AttributeError
when
sys
.
stderr
is
None
.
-
Issue
#
22419
:
Limit
the
length
of
incoming
HTTP
request
in
wsgiref
server
to
65536
bytes
and
send
a
414
error
code
for
higher
lengths
.
Patch
contributed
by
Devin
Cook
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment