From 0f6ce8d9dfaaeca036a085ef8de252efa8a2beea Mon Sep 17 00:00:00 2001 From: Stefan Krah Date: Mon, 26 Mar 2012 15:05:22 +0200 Subject: Issue #3367: NULL-terminate argv[] copies to prevent an invalid access in sys_update_path(). --- Modules/python.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Modules/python.c b/Modules/python.c index 935908a..cf9383f 100644 --- a/Modules/python.c +++ b/Modules/python.c @@ -22,9 +22,9 @@ extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size); int main(int argc, char **argv) { - wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); + wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); /* We need a second copies, as Python might modify the first one. */ - wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); + wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); int i, res; char *oldloc; /* 754 requires that FP exceptions run in "no stop" mode by default, @@ -58,6 +58,8 @@ main(int argc, char **argv) } argv_copy2[i] = argv_copy[i]; } + argv_copy2[argc] = argv_copy[argc] = NULL; + setlocale(LC_ALL, oldloc); free(oldloc); res = Py_Main(argc, argv_copy); -- cgit v0.12 From 8ece80faae3bec86628aa4176a751265ecb2f2a4 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 26 Mar 2012 17:09:58 +0100 Subject: Minor documentation tweak. --- Doc/library/logging.handlers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst index c4dd438..ef65cfa 100644 --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -654,7 +654,7 @@ event of a certain severity or greater is seen. :class:`BufferingHandler`, which is an abstract class. This buffers logging records in memory. Whenever each record is added to the buffer, a check is made by calling :meth:`shouldFlush` to see if the buffer should be flushed. If it -should, then :meth:`flush` is expected to do the needful. +should, then :meth:`flush` is expected to do the flushing. .. class:: BufferingHandler(capacity) -- cgit v0.12 From 99e7d0706eb4c424be6e648f1b3b69dba6b5aa34 Mon Sep 17 00:00:00 2001 From: Sandro Tosi Date: Mon, 26 Mar 2012 19:36:23 +0200 Subject: Issue #14410: fix typo in argparse doc; patch by Tshepang Lekhonkhobe --- Doc/library/argparse.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 79a98cb..b84e5c8 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1642,8 +1642,8 @@ Argument groups --bar BAR bar help - Note that any arguments not your user defined groups will end up back in the - usual "positional arguments" and "optional arguments" sections. + Note that any arguments not in your user-defined groups will end up back + in the usual "positional arguments" and "optional arguments" sections. Mutual exclusion -- cgit v0.12 From d86440750f7f81a024a9bb2e9053b290ec9b40d4 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 27 Mar 2012 07:46:46 +0200 Subject: Closes #14411: remove outdated comment in rlcompleter docstring. --- Lib/rlcompleter.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py index 8b74ffa..d3a4437 100644 --- a/Lib/rlcompleter.py +++ b/Lib/rlcompleter.py @@ -1,13 +1,11 @@ -"""Word completion for GNU readline 2.0. +"""Word completion for GNU readline. -This requires the latest extension to the readline module. The completer -completes keywords, built-ins and globals in a selectable namespace (which -defaults to __main__); when completing NAME.NAME..., it evaluates (!) the -expression up to the last dot and completes its attributes. +The completer completes keywords, built-ins and globals in a selectable +namespace (which defaults to __main__); when completing NAME.NAME..., it +evaluates (!) the expression up to the last dot and completes its attributes. -It's very cool to do "import sys" type "sys.", hit the -completion key (twice), and see the list of names defined by the -sys module! +It's very cool to do "import sys" type "sys.", hit the completion key (twice), +and see the list of names defined by the sys module! Tip: to use the tab key as the completion key, call @@ -15,21 +13,19 @@ Tip: to use the tab key as the completion key, call Notes: -- Exceptions raised by the completer function are *ignored* (and -generally cause the completion to fail). This is a feature -- since -readline sets the tty device in raw (or cbreak) mode, printing a -traceback wouldn't work well without some complicated hoopla to save, -reset and restore the tty state. +- Exceptions raised by the completer function are *ignored* (and generally cause + the completion to fail). This is a feature -- since readline sets the tty + device in raw (or cbreak) mode, printing a traceback wouldn't work well + without some complicated hoopla to save, reset and restore the tty state. -- The evaluation of the NAME.NAME... form may cause arbitrary -application defined code to be executed if an object with a -__getattr__ hook is found. Since it is the responsibility of the -application (or the user) to enable this feature, I consider this an -acceptable risk. More complicated expressions (e.g. function calls or -indexing operations) are *not* evaluated. +- The evaluation of the NAME.NAME... form may cause arbitrary application + defined code to be executed if an object with a __getattr__ hook is found. + Since it is the responsibility of the application (or the user) to enable this + feature, I consider this an acceptable risk. More complicated expressions + (e.g. function calls or indexing operations) are *not* evaluated. - When the original stdin is not a tty device, GNU readline is never -used, and this module (and the readline module) are silently inactive. + used, and this module (and the readline module) are silently inactive. """ -- cgit v0.12 From 07cf1d8085e40840459df877ddaded7c539a6806 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Thu, 29 Mar 2012 06:47:35 -0400 Subject: #14416: add missing LOG_SYSLOG facility to syslog docs. --- Doc/library/syslog.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/syslog.rst b/Doc/library/syslog.rst index 795d66d..645c326 100644 --- a/Doc/library/syslog.rst +++ b/Doc/library/syslog.rst @@ -78,7 +78,8 @@ Priority levels (high to low): Facilities: :const:`LOG_KERN`, :const:`LOG_USER`, :const:`LOG_MAIL`, :const:`LOG_DAEMON`, :const:`LOG_AUTH`, :const:`LOG_LPR`, :const:`LOG_NEWS`, :const:`LOG_UUCP`, - :const:`LOG_CRON` and :const:`LOG_LOCAL0` to :const:`LOG_LOCAL7`. + :const:`LOG_CRON`, :const:`LOG_SYSLOG` and :const:`LOG_LOCAL0` to + :const:`LOG_LOCAL7`. Log options: :const:`LOG_PID`, :const:`LOG_CONS`, :const:`LOG_NDELAY`, :const:`LOG_NOWAIT` -- cgit v0.12 From 67ac0792037349b01ab2193ea9a057ffc420239e Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 29 Mar 2012 19:01:28 +0300 Subject: Issue #14409: IDLE doesn't not execute commands from shell with default keybinding for . Patch by Roger Serwy. --- Lib/idlelib/NEWS.txt | 3 +++ Lib/idlelib/configHandler.py | 2 +- Misc/NEWS | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index 4482be2..f7fbe45 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -1,6 +1,9 @@ What's New in IDLE 3.2.3? ========================= +- Issue #14409: IDLE doesn't not execute commands from shell, + error with default keybinding for Return. (Patch by Roger Serwy) + - Issue #3573: IDLE hangs when passing invalid command line args (directory(ies) instead of file(s)). diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py index 73b8db5..da92726 100644 --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -595,7 +595,7 @@ class IdleConf: '<>': [''], '<>': [''], '<>': [''], - '<>': [' '], + '<>': ['', ''], '<>': [''], '<>': [''], '<>': [''], diff --git a/Misc/NEWS b/Misc/NEWS index e3b110d..f4a2d03 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -31,6 +31,9 @@ Core and Builtins Library ------- +- Issue #14409: IDLE doesn't not execute commands from shell, + error with default keybinding for Return. (Patch by Roger Serwy) + - Issue #10340: asyncore - properly handle EINVAL in dispatcher constructor on OSX; avoid to call handle_connect in case of a disconnected socket which was not meant to connect. -- cgit v0.12 From 6f5e54e76915d9a8767f7241f0e835116877e6e5 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 29 Mar 2012 20:17:18 +0100 Subject: Closes #14436: Convert msg + args to string before pickling. --- Lib/logging/handlers.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index fed8c93..7689b04 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -519,11 +519,16 @@ class SocketHandler(logging.Handler): """ ei = record.exc_info if ei: - dummy = self.format(record) # just to get traceback text into record.exc_text - record.exc_info = None # to avoid Unpickleable error - s = pickle.dumps(record.__dict__, 1) - if ei: - record.exc_info = ei # for next handler + # just to get traceback text into record.exc_text ... + dummy = self.format(record) + # See issue #14436: If msg or args are objects, they may not be + # available on the receiving end. So we convert the msg % args + # to a string, save it as msg and zap the args. + d = dict(record.__dict__) + d['msg'] = record.getMessage() + d['args'] = None + d['exc_info'] = None + s = pickle.dumps(d, 1) slen = struct.pack(">L", len(s)) return slen + s -- cgit v0.12 From 5e0c57142d7380d7209f198f772bb9851739652d Mon Sep 17 00:00:00 2001 From: R David Murray Date: Fri, 30 Mar 2012 18:07:42 -0400 Subject: #10423: clarify options vs args in argparse discussion of optparse Patch by Sandro Tosi. --- Doc/library/argparse.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index b84e5c8..0123b5c 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1833,9 +1833,10 @@ A partial upgrade path from :mod:`optparse` to :mod:`argparse`: * Replace all :meth:`optparse.OptionParser.add_option` calls with :meth:`ArgumentParser.add_argument` calls. -* Replace ``options, args = parser.parse_args()`` with ``args = +* Replace ``(options, args) = parser.parse_args()`` with ``args = parser.parse_args()`` and add additional :meth:`ArgumentParser.add_argument` - calls for the positional arguments. + calls for the positional arguments. Keep in mind that what was previously + called ``options``, now in :mod:`argparse` context is called ``args``. * Replace callback actions and the ``callback_*`` keyword arguments with ``type`` or ``action`` arguments. -- cgit v0.12 From f3c297675d591a7e1ef3a97e7df346615d64ad4f Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sat, 31 Mar 2012 14:10:10 +0300 Subject: update NEWS as Terry Reedy proposed --- Lib/idlelib/NEWS.txt | 6 ++++-- Misc/NEWS | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index f7fbe45..a6b06b4 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -1,8 +1,10 @@ What's New in IDLE 3.2.3? ========================= -- Issue #14409: IDLE doesn't not execute commands from shell, - error with default keybinding for Return. (Patch by Roger Serwy) +- Issue #14409: IDLE now properly executes commands in the Shell window + when it cannot read the normal config files on startup and + has to use the built-in default key bindings. + There was previously a bug in one of the defaults. - Issue #3573: IDLE hangs when passing invalid command line args (directory(ies) instead of file(s)). diff --git a/Misc/NEWS b/Misc/NEWS index f4a2d03..d084fac 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -31,8 +31,10 @@ Core and Builtins Library ------- -- Issue #14409: IDLE doesn't not execute commands from shell, - error with default keybinding for Return. (Patch by Roger Serwy) +- Issue #14409: IDLE now properly executes commands in the Shell window + when it cannot read the normal config files on startup and + has to use the built-in default key bindings. + There was previously a bug in one of the defaults. - Issue #10340: asyncore - properly handle EINVAL in dispatcher constructor on OSX; avoid to call handle_connect in case of a disconnected socket which -- cgit v0.12 From 9ee65f1f9247c49b0ab52ef9beef1ca4b0503bfc Mon Sep 17 00:00:00 2001 From: Sandro Tosi Date: Sat, 31 Mar 2012 17:23:10 +0200 Subject: add 'safari' to webbrowser browsers table; thanks to Jonathan Eunice from docs@ --- Doc/library/webbrowser.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst index 23ba6c5..dfb09ee 100644 --- a/Doc/library/webbrowser.rst +++ b/Doc/library/webbrowser.rst @@ -137,6 +137,8 @@ for the controller classes, all defined in this module. +-----------------------+-----------------------------------------+-------+ | ``'macosx'`` | :class:`MacOSX('default')` | \(4) | +-----------------------+-----------------------------------------+-------+ +| ``'safari'`` | :class:`MacOSX('safari')` | \(4) | ++-----------------------+-----------------------------------------+-------+ Notes: -- cgit v0.12 From de0f6297a703918d12a2f2c48bc44fcbc7946a13 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Sat, 31 Mar 2012 12:06:35 -0400 Subject: #14434: make tutorial link in 'help' banner version-specific Without this fix, both 2.7 and 3.x would always point to the "current" docs...which means that before this fix python 3.2 'help' pointed to the 2.7 tutorial. --- Lib/pydoc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index f45d461..89fd09b 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1829,7 +1829,7 @@ has the same effect as typing a particular string at the help> prompt. Welcome to Python %s! This is the online help utility. If this is your first time using Python, you should definitely check out -the tutorial on the Internet at http://docs.python.org/tutorial/. +the tutorial on the Internet at http://docs.python.org/%s/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and @@ -1839,7 +1839,7 @@ To get a list of available modules, keywords, or topics, type "modules", "keywords", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose summaries contain a given word such as "spam", type "modules spam". -''' % sys.version[:3]) +''' % tuple([sys.version[:3]]*2)) def list(self, items, columns=4, width=80): items = list(sorted(items)) -- cgit v0.12 From 317075de2981c9283e7af7bcf727ef8ae8ee4f4e Mon Sep 17 00:00:00 2001 From: Sandro Tosi Date: Sat, 31 Mar 2012 18:34:59 +0200 Subject: use unittest.skip; thanks to Chang Min Jeon from docs@ --- Doc/library/unittest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst index bdf07a4..b130a8b 100644 --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -640,7 +640,7 @@ This is the output of running the example above in verbose mode: :: Classes can be skipped just like methods: :: - @skip("showing class skipping") + @unittest.skip("showing class skipping") class MySkippedTestCase(unittest.TestCase): def test_not_run(self): pass -- cgit v0.12 From f70401e842d120407c5450d0b89cece8616af8e4 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 31 Mar 2012 20:23:30 +0200 Subject: Issue #14406: Fix a race condition when using `concurrent.futures.wait(return_when=ALL_COMPLETED)`. Patch by Matt Joiner. --- Lib/concurrent/futures/_base.py | 8 +++++--- Lib/test/test_concurrent_futures.py | 18 +++++++++++++++++- Misc/NEWS | 3 +++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py index 79b91d4..9f11f69 100644 --- a/Lib/concurrent/futures/_base.py +++ b/Lib/concurrent/futures/_base.py @@ -112,12 +112,14 @@ class _AllCompletedWaiter(_Waiter): def __init__(self, num_pending_calls, stop_on_exception): self.num_pending_calls = num_pending_calls self.stop_on_exception = stop_on_exception + self.lock = threading.Lock() super().__init__() def _decrement_pending_calls(self): - self.num_pending_calls -= 1 - if not self.num_pending_calls: - self.event.set() + with self.lock: + self.num_pending_calls -= 1 + if not self.num_pending_calls: + self.event.set() def add_result(self, future): super().add_result(future) diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 372da27..2afa938 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -183,7 +183,9 @@ class ProcessPoolShutdownTest(ProcessPoolMixin, ExecutorShutdownTest): for p in processes: p.join() + class WaitTests(unittest.TestCase): + def test_first_completed(self): future1 = self.executor.submit(mul, 21, 2) future2 = self.executor.submit(time.sleep, 1.5) @@ -284,7 +286,21 @@ class WaitTests(unittest.TestCase): class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests): - pass + + def test_pending_calls_race(self): + # Issue #14406: multi-threaded race condition when waiting on all + # futures. + event = threading.Event() + def future_func(): + event.wait() + oldswitchinterval = sys.getswitchinterval() + sys.setswitchinterval(1e-6) + try: + fs = {self.executor.submit(future_func) for i in range(100)} + event.set() + futures.wait(fs, return_when=futures.ALL_COMPLETED) + finally: + sys.setswitchinterval(oldswitchinterval) class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests): diff --git a/Misc/NEWS b/Misc/NEWS index d084fac..d814b17 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -31,6 +31,9 @@ Core and Builtins Library ------- +- Issue #14406: Fix a race condition when using ``concurrent.futures.wait( + return_when=ALL_COMPLETED)``. Patch by Matt Joiner. + - Issue #14409: IDLE now properly executes commands in the Shell window when it cannot read the normal config files on startup and has to use the built-in default key bindings. -- cgit v0.12 From 6afd11c762ad9f135ce7aaf1f9fa1e3856984bf1 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 31 Mar 2012 20:56:21 +0200 Subject: Issue #14456: improve documentation of the signal module w.r.t. threads. --- Doc/library/signal.rst | 92 ++++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/Doc/library/signal.rst b/Doc/library/signal.rst index 698b1e7..d1cae13 100644 --- a/Doc/library/signal.rst +++ b/Doc/library/signal.rst @@ -5,46 +5,58 @@ :synopsis: Set handlers for asynchronous events. -This module provides mechanisms to use signal handlers in Python. Some general -rules for working with signals and their handlers: - -* A handler for a particular signal, once set, remains installed until it is - explicitly reset (Python emulates the BSD style interface regardless of the - underlying implementation), with the exception of the handler for - :const:`SIGCHLD`, which follows the underlying implementation. - -* There is no way to "block" signals temporarily from critical sections (since - this is not supported by all Unix flavors). - -* Although Python signal handlers are called asynchronously as far as the Python - user is concerned, they can only occur between the "atomic" instructions of the - Python interpreter. This means that signals arriving during long calculations - implemented purely in C (such as regular expression matches on large bodies of - text) may be delayed for an arbitrary amount of time. - -* When a signal arrives during an I/O operation, it is possible that the I/O - operation raises an exception after the signal handler returns. This is - dependent on the underlying Unix system's semantics regarding interrupted system - calls. - -* Because the C signal handler always returns, it makes little sense to catch - synchronous errors like :const:`SIGFPE` or :const:`SIGSEGV`. - -* Python installs a small number of signal handlers by default: :const:`SIGPIPE` - is ignored (so write errors on pipes and sockets can be reported as ordinary - Python exceptions) and :const:`SIGINT` is translated into a - :exc:`KeyboardInterrupt` exception. All of these can be overridden. - -* Some care must be taken if both signals and threads are used in the same - program. The fundamental thing to remember in using signals and threads - simultaneously is: always perform :func:`signal` operations in the main thread - of execution. Any thread can perform an :func:`alarm`, :func:`getsignal`, - :func:`pause`, :func:`setitimer` or :func:`getitimer`; only the main thread - can set a new signal handler, and the main thread will be the only one to - receive signals (this is enforced by the Python :mod:`signal` module, even - if the underlying thread implementation supports sending signals to - individual threads). This means that signals can't be used as a means of - inter-thread communication. Use locks instead. +This module provides mechanisms to use signal handlers in Python. + + +General rules +------------- + +The :func:`signal.signal` function allows to define custom handlers to be +executed when a signal is received. A small number of default handlers are +installed: :const:`SIGPIPE` is ignored (so write errors on pipes and sockets +can be reported as ordinary Python exceptions) and :const:`SIGINT` is +translated into a :exc:`KeyboardInterrupt` exception. + +A handler for a particular signal, once set, remains installed until it is +explicitly reset (Python emulates the BSD style interface regardless of the +underlying implementation), with the exception of the handler for +:const:`SIGCHLD`, which follows the underlying implementation. + +There is no way to "block" signals temporarily from critical sections (since +this is not supported by all Unix flavors). + + +Execution of Python signal handlers +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +A Python signal handler does not get executed inside the low-level (C) signal +handler. Instead, the low-level signal handler sets a flag which tells the +:term:`virtual machine` to execute the corresponding Python signal handler +at a later point(for example at the next :term:`bytecode` instruction). +This has consequences: + +* It makes little sense to catch synchronous errors like :const:`SIGFPE` or + :const:`SIGSEGV`. + +* A long-running calculation implemented purely in C (such as regular + expression matching on a large body of text) may run uninterrupted for an + arbitrary amount of time, regardless of any signals received. The Python + signal handlers will be called when the calculation finishes. + + +Signals and threads +^^^^^^^^^^^^^^^^^^^ + +Python signal handlers are always executed in the main Python thread, +even if the signal was received in another thread. This means that signals +can't be used as a means of inter-thread communication. You can use +the synchronization primitives from the :mod:`threading` module instead. + +Besides, only the main thread is allowed to set a new signal handler. + + +Module contents +--------------- The variables defined in the :mod:`signal` module are: -- cgit v0.12 From 6211b881613de6654ec8b5e77f3c705f1b4becb8 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 31 Mar 2012 23:50:31 +0200 Subject: Issue #14437: Fix building the _io module under Cygwin. --- Misc/NEWS | 2 ++ Modules/_io/_iomodule.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index d814b17..07eea72 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -105,6 +105,8 @@ Extension Modules Build ----- +- Issue #14437: Fix building the _io module under Cygwin. + - Issue #14387: Do not include accu.h from Python.h. - Issue #14359: Only use O_CLOEXEC in _posixmodule.c if it is defined. diff --git a/Modules/_io/_iomodule.h b/Modules/_io/_iomodule.h index 925e4f2..c198b43 100644 --- a/Modules/_io/_iomodule.h +++ b/Modules/_io/_iomodule.h @@ -67,7 +67,7 @@ typedef struct { PyObject *filename; /* Not used, but part of the IOError object */ Py_ssize_t written; } PyBlockingIOErrorObject; -PyAPI_DATA(PyObject *) PyExc_BlockingIOError; +extern PyObject *PyExc_BlockingIOError; /* * Offset type for positioning. -- cgit v0.12 From 70deb3de3960142fcf8497d2ea0cfae6609b8e66 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 1 Apr 2012 01:00:17 +0200 Subject: Issue #13872: socket.detach() now marks the socket closed (as mirrored in the socket repr()). Patch by Matt Joiner. --- Lib/socket.py | 11 +++++++++++ Lib/test/test_socket.py | 1 + Misc/NEWS | 3 +++ 3 files changed, 15 insertions(+) diff --git a/Lib/socket.py b/Lib/socket.py index 1e28549..a93cd11 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -197,6 +197,17 @@ class socket(_socket.socket): if self._io_refs <= 0: self._real_close() + def detach(self): + """detach() -> file descriptor + + Close the socket object without closing the underlying file descriptor. + The object cannot be used after this call, but the file descriptor + can be reused for other purposes. The file descriptor is returned. + """ + self._closed = True + return super().detach() + + def fromfd(fd, family, type, proto=0): """ fromfd(fd, family, type[, proto]) -> socket object diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index d77b7dc..cce0d1b 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -951,6 +951,7 @@ class BasicTCPTest(SocketConnectedTest): f = self.cli_conn.detach() self.assertEqual(f, fileno) # cli_conn cannot be used anymore... + self.assertTrue(self.cli_conn._closed) self.assertRaises(socket.error, self.cli_conn.recv, 1024) self.cli_conn.close() # ...but we can create another socket using the (still open) diff --git a/Misc/NEWS b/Misc/NEWS index 07eea72..32c0b9e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -31,6 +31,9 @@ Core and Builtins Library ------- +- Issue #13872: socket.detach() now marks the socket closed (as mirrored + in the socket repr()). Patch by Matt Joiner. + - Issue #14406: Fix a race condition when using ``concurrent.futures.wait( return_when=ALL_COMPLETED)``. Patch by Matt Joiner. -- cgit v0.12 From 165a2c2e27c07ac0c1ab5092a79f7f30c6c2a0d6 Mon Sep 17 00:00:00 2001 From: Sandro Tosi Date: Sun, 1 Apr 2012 01:50:00 +0200 Subject: fix typo; thanks to Robert Bardos from docs@ --- Doc/glossary.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/glossary.rst b/Doc/glossary.rst index 2f1277c..21b92a9 100644 --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -385,7 +385,7 @@ Glossary :meth:`str.lower` method can serve as a key function for case insensitive sorts. Alternatively, an ad-hoc key function can be built from a :keyword:`lambda` expression such as ``lambda r: (r[0], r[2])``. Also, - the :mod:`operator` module provides three key function constuctors: + the :mod:`operator` module provides three key function constructors: :func:`~operator.attrgetter`, :func:`~operator.itemgetter`, and :func:`~operator.methodcaller`. See the :ref:`Sorting HOW TO ` for examples of how to create and use key functions. -- cgit v0.12 From 58bb82e7b4b50fa5efaefc1196bd927992fbe783 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 1 Apr 2012 16:05:46 +0200 Subject: Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch by Suman Saha. --- Misc/NEWS | 3 +++ Objects/bytearrayobject.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 32c0b9e..4bf3a91 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.2.4 Core and Builtins ----------------- +- Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch + by Suman Saha. + - Issue #14378: Fix compiling ast.ImportFrom nodes with a "__future__" string as the module name that was not interned. diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 4202ff2..55b4df6 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2234,8 +2234,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *arg) } bytearray_obj = PyByteArray_FromStringAndSize(NULL, buf_size); - if (bytearray_obj == NULL) + if (bytearray_obj == NULL) { + Py_DECREF(it); return NULL; + } buf = PyByteArray_AS_STRING(bytearray_obj); while ((item = PyIter_Next(it)) != NULL) { @@ -2268,8 +2270,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *arg) return NULL; } - if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), bytearray_obj) == -1) + if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), bytearray_obj) == -1) { + Py_DECREF(bytearray_obj); return NULL; + } Py_DECREF(bytearray_obj); Py_RETURN_NONE; -- cgit v0.12 From 709176f10c1774f608a318171a94371e7d05d98f Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 1 Apr 2012 17:19:09 +0200 Subject: Issue #14151: Raise a ValueError, not a NameError, when trying to create a multiprocessing Client or Listener with an AF_PIPE type address under non-Windows platforms. Patch by Popa Claudiu. --- Lib/multiprocessing/connection.py | 9 +++++++++ Lib/test/test_multiprocessing.py | 14 +++++++++++++- Misc/NEWS | 4 ++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index df00f1d..fa6f7b3 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -94,6 +94,13 @@ def arbitrary_address(family): else: raise ValueError('unrecognized family') +def _validate_family(family): + ''' + Checks if the family is valid for the current environment. + ''' + if sys.platform != 'win32' and family == 'AF_PIPE': + raise ValueError('Family %s is not recognized.' % family) + def address_type(address): ''' @@ -126,6 +133,7 @@ class Listener(object): or default_family address = address or arbitrary_address(family) + _validate_family(family) if family == 'AF_PIPE': self._listener = PipeListener(address, backlog) else: @@ -163,6 +171,7 @@ def Client(address, family=None, authkey=None): Returns a connection to the address of a `Listener` ''' family = family or address_type(address) + _validate_family(family) if family == 'AF_PIPE': c = PipeClient(address) else: diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index 8edb420..8de7a8d 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -2319,8 +2319,20 @@ class TestStdinBadfiledescriptor(unittest.TestCase): flike.flush() assert sio.getvalue() == 'foo' + +# +# Issue 14151: Test invalid family on invalid environment +# + +class TestInvalidFamily(unittest.TestCase): + + @unittest.skipIf(WIN32, "skipped on Windows") + def test_invalid_family(self): + with self.assertRaises(ValueError): + multiprocessing.connection.Listener(r'\\.\test') + testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, - TestStdinBadfiledescriptor] + TestStdinBadfiledescriptor, TestInvalidFamily] # # diff --git a/Misc/NEWS b/Misc/NEWS index 4bf3a91..2fa911e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -34,6 +34,10 @@ Core and Builtins Library ------- +- Issue #14151: Raise a ValueError, not a NameError, when trying to create + a multiprocessing Client or Listener with an AF_PIPE type address under + non-Windows platforms. Patch by Popa Claudiu. + - Issue #13872: socket.detach() now marks the socket closed (as mirrored in the socket repr()). Patch by Matt Joiner. -- cgit v0.12