Victor Stinner [Sat, 26 Mar 2016 00:04:37 +0000 (01:04 +0100)]
makeopcodetargets.py: we need to import Lib/opcode.py
Issue #20021: use importlib.machinery to import Lib/opcode.py and not an opcode
module coming from somewhere else. makeopcodetargets.py is part of the Python
build process and it is run by an external Python program, not the built Python
program.
Victor Stinner [Fri, 25 Mar 2016 16:36:33 +0000 (17:36 +0100)]
Rework libregrtest.save_env
* Replace get/restore methods with a Resource class and Resource subclasses
* Create ModuleAttr, ModuleAttrList and ModuleAttrDict helper classes
* Use __subclasses__() to get resource classes instead of using an hardcoded
list (2 shutil resources were missinged in the list!)
* Don't define MultiprocessingProcessDangling resource if the multiprocessing
module is missing
* Nicer diff for dictionaries. Useful for the big os.environ dict
* Reorder code to group resources
Victor Stinner [Fri, 25 Mar 2016 10:54:47 +0000 (11:54 +0100)]
Modernize Python/makeopcodetargets.py
* Simply use "import opcode" to import the opcode module instead of tricks
using the imp module
* Use context manager for the output file
* Move code into a new main() function
* Replace assert with a regular if to check the number of arguments
* Import modules at top level
Victor Stinner [Fri, 25 Mar 2016 08:29:50 +0000 (09:29 +0100)]
Issue #25654:
* multiprocessing: open file with closefd=False to avoid ResourceWarning
* _test_multiprocessing: open file with O_EXCL to detect bugs in tests (if a
previous test forgot to remove TESTFN)
* test_sys_exit(): remove TESTFN after each loop iteration
Victor Stinner [Fri, 25 Mar 2016 08:29:50 +0000 (09:29 +0100)]
Issue #25654:
* multiprocessing: open file with closefd=False to avoid ResourceWarning
* _test_multiprocessing: open file with O_EXCL to detect bugs in tests (if a
previous test forgot to remove TESTFN)
* test_sys_exit(): remove TESTFN after each loop iteration
Victor Stinner [Thu, 24 Mar 2016 23:40:59 +0000 (00:40 +0100)]
Fix bug in __import__ during Python shutdown
Issue #26637: The importlib module now emits an ImportError rather than a
TypeError if __import__() is tried during the Python shutdown process but
sys.path is already cleared (set to None).
Victor Stinner [Thu, 24 Mar 2016 23:33:12 +0000 (00:33 +0100)]
Merge 3.5
Issue #21925: warnings.formatwarning() now catches exceptions when calling
linecache.getline() and tracemalloc.get_object_traceback() to be able to log
ResourceWarning emitted late during the Python shutdown process.
Victor Stinner [Thu, 24 Mar 2016 23:30:32 +0000 (00:30 +0100)]
warnings.formatwarning(): catch exceptions
Issue #21925: warnings.formatwarning() now catches exceptions on
linecache.getline(...) to be able to log ResourceWarning emitted late during
the Python shutdown process.
Victor Stinner [Thu, 24 Mar 2016 16:53:20 +0000 (17:53 +0100)]
Cleanup regrtest "main()" function
* Rename libregrtest.main_in_temp_cwd() to libregrtest.main()
* Add regrtest.main_in_temp_cwd() alias to libregrtest.main()
* Move old main_in_temp_cwd() code into libregrtest.Regrtest.main()
* Update multiple scripts to call libregrtest.main()
Victor Stinner [Thu, 24 Mar 2016 16:12:55 +0000 (17:12 +0100)]
Enhance and modernize test_os
* add create_file() helper function
* create files using "x" mode instead of "w" to detect when a previous test
forget to remove a file
* open file for writing in unbuferred mode (buffering=0)
* replace "try/finally: unlink" with self.addCleanup(support.unlink)
* register unlink cleanup function *before* creating new files
Victor Stinner [Thu, 24 Mar 2016 12:55:58 +0000 (13:55 +0100)]
Closes #26620: Fix ResourceWarning in test_urllib2_localnet
* Use context manager on urllib objects to ensure that they are closed on error
* Use self.addCleanup() to cleanup resources even if a test is interrupted
with CTRL+c
Victor Stinner [Thu, 24 Mar 2016 12:44:19 +0000 (13:44 +0100)]
Enhance and modernize test_genericpath
* Replace "try/finally: os.remove()" with self.addCleanup(support.unlink) or
self.addCleanup(support.rmdir): the support function handles the case when
the file doesn't exist
* Replace "try/finally: f.close()" with "with open(...) as f:"
* test_getsize: add a second test with a different size
* Create file using "x" mode to ensure that the file didn't exist before, to
detect bugs in tests
* Open files in unbuffered mode (buferring=0) to write immediatly data on disk
* Replace map() with simpler code
* Split isdir() unit test into two units tests to make them less dependant,
same change for isfile() test
* test_samefile(): test also two different files
Victor Stinner [Thu, 24 Mar 2016 11:23:18 +0000 (12:23 +0100)]
Enhance os._DummyDirEntry
Issue #25911:
* Try to fix test_os.BytesWalkTests on Windows
* Try to mimick better the reference os.DirEntry on Windows
* _DummyDirEntry now caches os.stat() result
* _DummyDirEntry constructor now tries to get os.stat()
Victor Stinner [Wed, 23 Mar 2016 21:03:55 +0000 (22:03 +0100)]
_tracemalloc: use compact key for traces
Issue #26588: Optimize memory footprint of _tracemalloc before non-zero domain
is used. Start with compact key (Py_uintptr_t) and also switch to pointer_t key
when the first memory block with a non-zero domain is tracked.
Victor Stinner [Wed, 23 Mar 2016 13:44:14 +0000 (14:44 +0100)]
faulthandler: only log fatal exceptions
Issue #23848, #26622:
* faulthandler now only logs fatal Windows exceptions.
* write error code as decimal, not as hexadecimal
* replace "Windows exception" with "Windows fatal exception"
Victor Stinner [Wed, 23 Mar 2016 09:39:17 +0000 (10:39 +0100)]
faulthandler: add Windows exception handler
Issue #23848: On Windows, faulthandler.enable() now also installs an exception
handler to dump the traceback of all Python threads on any Windows exception,
not only on UNIX signals (SIGSEGV, SIGFPE, SIGABRT).
Victor Stinner [Wed, 23 Mar 2016 08:52:13 +0000 (09:52 +0100)]
Cleanup hashtable.h
Issue #26588:
* Pass the hash table rather than the key size to hash and compare functions
* _Py_HASHTABLE_READ_KEY() and _Py_HASHTABLE_ENTRY_READ_KEY() macros now expect
the hash table as the first parameter, rather than the key size
* tracemalloc_get_traces_fill(): use _Py_HASHTABLE_ENTRY_READ_DATA() rather
than pointer dereference
* Remove the _Py_HASHTABLE_ENTRY_WRITE_PKEY() macro
* Move "PKEY" and "PDATA" macros inside hashtable.c
Victor Stinner [Wed, 23 Mar 2016 08:38:54 +0000 (09:38 +0100)]
Issue #26588:
* Optimize tracemalloc_add_trace(): modify hashtable entry data (trace) if the
memory block is already tracked, rather than trying to remove the old trace
and then add a new trace.
* Add _Py_HASHTABLE_ENTRY_WRITE_DATA() macro
Victor Stinner [Wed, 23 Mar 2016 01:05:39 +0000 (02:05 +0100)]
Makefile: change default value of TESTTIMEOUT from 1 hour to 15 min
The whole test suite takes 6 minutes on my laptop. It takes less than 30
minutes on most buildbots. The TESTTIMEOUT is the timeout for a single test
file.
Victor Stinner [Tue, 22 Mar 2016 23:54:48 +0000 (00:54 +0100)]
_warnings.warn_explicit(): try to import warnings
Issue #26592: _warnings.warn_explicit() now tries to import the warnings module
(Python implementation) if the source parameter is set to be able to log the
traceback where the source was allocated.
Victor Stinner [Tue, 22 Mar 2016 23:43:54 +0000 (00:43 +0100)]
Implement finalizer for os.scandir() iterator
Issue #26603:
* Implement finalizer for os.scandir() iterator
* Set the source parameter when emitting the ResourceWarning warning
* Close the iterator before emitting the warning
Victor Stinner [Tue, 22 Mar 2016 23:28:08 +0000 (00:28 +0100)]
Add a source parameter to warnings.warn()
Issue #26604:
* Add a new optional source parameter to _warnings.warn() and warnings.warn()
* Modify asyncore, asyncio and _pyio modules to set the source parameter when
logging a ResourceWarning warning
Victor Stinner [Tue, 22 Mar 2016 23:10:24 +0000 (00:10 +0100)]
Fix _tracemalloc start/stop
Issue #26588: Fix _tracemalloc start/stop: don't play with the reentrant flag.
set_reentrant(1) fails with an assertion error if tracemalloc_init() is called
first in a thread A and tracemalloc_start() is called second in a thread B. The
tracemalloc is imported in a thread A. Importing the module calls
tracemalloc_init(). tracemalloc.start() is called in a thread B.
Victor Stinner [Tue, 22 Mar 2016 12:39:05 +0000 (13:39 +0100)]
Add C functions _PyTraceMalloc_Track()
Issue #26530:
* Add C functions _PyTraceMalloc_Track() and _PyTraceMalloc_Untrack() to track
memory blocks using the tracemalloc module.
* Add _PyTraceMalloc_GetTraceback() to get the traceback of an object.