Re: How to Add ANSI Color to User Response
On Thu, 11 Apr 2024 05:00:32 +0200 Gisle Vanem via Python-list wrote: >Pierre Fortin wrote: > >> Over the years, I've tried different mechanisms for applying colors until >> I got my hands on f-stings; then I created a tiny module with all the >> colors (cR, cG, etc) which made my life so much simpler (attached). > >Attachments are stripped off in this list. >It would be nice to see this tiny module of yours. >An URL or attach as inline text please. #!/bin/python # -*- mode: python; -*- # Copyright: #2024-Present, Pierre Fortin # License: #GPLv3 or any later version: https://www.gnu.org/licenses/gpl-3.0.en.html # Created: #2023-11-10 Initial script # Updated: # Usage: f"{cR}red text {cG}green text{cO}; colors off" #or: print( cY, "yellow text", cO ) # VT100 type terminal colors ESC = "\u001b"; # Foreground Colors _black = f"{ESC}[30m"; _red = f"{ESC}[31m"; _green = f"{ESC}[32m"; _yellow = f"{ESC}[33m" _blue = f"{ESC}[34m"; _magenta = f"{ESC}[35m"; _cyan = f"{ESC}[36m"; _white = f"{ESC}[37m" # Background Colors _black_ = f"{ESC}[40m"; _red_ = f"{ESC}[41m"; _green_ = f"{ESC}[42m"; _yellow_ = f"{ESC}[43m" _blue_ = f"{ESC}[44m"; _magenta_ = f"{ESC}[45m"; _cyan_ = f"{ESC}[46m"; _white_ = f"{ESC}[47m" _off = f"{ESC}[0m" ANSIEraseLine = '\033[2K\033[1G' EL = ANSIEraseLine # short alias # Color abbreviations (shortcuts for f-sting use) cK=_black; cR=_red; cG=_green; cY=_yellow; cB=_blue; cM=_magenta; cC=_cyan; cW=_white; cO=_off # background colors; use {cO} to turn off any color bK=_black_; bR=_red_; bG=_green_; bY=_yellow_; bB=_blue_; bM=_magenta_; bC=_cyan_; bW=_white_ -- https://mail.python.org/mailman/listinfo/python-list
Re: How to Add ANSI Color to User Response
On Thu, 11 Apr 2024 04:50:49 +1000 WordWeaver Evangelist via Python-list wrote: >Hello List, > >I have a simple question. I use the following textPrompt in some of my Jython >modules: > '\n[1;33mYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, > forceUppercase=True) >Is there a way to add an ANSI color code to the end where the conditions are, >so that the color of the user’s input is of a color of my choosing, instead of >just white? >Thank you very much in advance. >Kind regards, >Bill Kochman Over the years, I've tried different mechanisms for applying colors until I got my hands on f-stings; then I created a tiny module with all the colors (cR, cG, etc) which made my life so much simpler (attached). The module includes background colors (bX); but I very rarely use those. Then, I just use the module like this: # place the module in a directory where your script is # e.g., $ mkdir mymods (rename as desired) from mymods.colors import * # or just include the contents inline # this simply switches from one color to the next print( f"{cR}red, {cB}blue, {cG}green {cO}are colors." ) # color just the response ans = input( f"Answer?: {cG}" ) # turn off color on next line print( f"{cO}You entered: {cY}{ans}{cO}" ) # # to turn off each color (white commas), change the above to: print( f"{cR}red{cO}, {cB}blue{cO}, {cG}green {cO}are colors." ) On Windows, you'll need to add this *before* using the colors: import os if os.name == 'nt': # Only if we are running on Windows from ctypes import windll w = windll.kernel32 # enable ANSI VT100 colors on Windows. w.SetConsoleMode(w.GetStdHandle(-11), 7) HTH, Pierre -- https://mail.python.org/mailman/listinfo/python-list
Re: Newline (NuBe Question)
On Wed, 15 Nov 2023 16:51:09 - Grizzy Adams via Python-list wrote: I don't give solutions; just a nudge... you appear not to fully grok "list"; your list is ONE list with no delineation between students. You want a "list of lists"... >['Example High', 'Mary', 89.6, 'Pass', 'Example High', 'Matthew', 76.5, >'Fail', 'Example High', 'Marie', 80.4, 'Fail', 'Example High', 'Manuel', 79.6, >'Fail', 'Example High', 'Malala', 98.9, 'Pass'] Like this: students = [ ['Example High', 'Mary', 89.6, 'Pass'], ['Example High','Matthew', 76.5, 'Fail'], ['Example High', 'Marie', 80.4, 'Fail'], ['Example High', 'Manuel', 79.6, 'Fail'], ['Example High', 'Malala', 98.9, 'Pass'] ] This may help get you headed in the right direction: for s in students: print( s ) Hint: look forward to learning about f-strings... HTH, Pierre -- https://mail.python.org/mailman/listinfo/python-list
[Python-announce] ANN: Release of PlotPy V2
PlotPy V2 distinguishes itself in the realm of plotting libraries. Designed for Python/Qt applications, this library offers a blend of superior performance and enhanced interactive features. Its image display features, driven by a C++ transform engine, include real-time high-quality interpolation, LUT, and geometric transformations, elevating data interaction. PlotPy is part of the PlotPyStack project (<https://github.com/PlotPyStack>), dedicated to delivering a comprehensive toolkit for crafting scientific and technical data visualization applications. The development efforts for PlotPy V2 were financed by the CEA (< https://www.cea.fr/>). What's New in PlotPy V2 : Major Updates: Refined and unified API for curve and image plotting features (widget, dialog, window). Introduction of a new window for synchronized multi-plot displays . Enhancements: Expanded Image Lookup Table functionalities. Integration of SVG-based shapes. Documentation: Comprehensive Sphinx-based documentation enriched with API links, examples, and tutorials. ⚙️ Development Features: Black code formatting, robust `pytest`-based automated test suite, and a 70% test coverage milestone ✅. We invite the community to explore PlotPy V2's capabilities. Explore PlotPy V2 on PyPI: <https://pypi.org/project/PlotPy/>. View the project on GitHub: <https://github.com/PlotPyStack/plotpy/>. Review the documentation: <https://plotpy.readthedocs.io/en/latest/>. Cheers, Pierre ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com
iterations destroy reversed() results
Hi, reversed() results are fine until iterated over, after which the results are no longer available. This was discovered after using something like this: rev = reversed( sorted( list ) ) sr = sum( 1 for _ in rev ) # rev is now destroyed So reversed() results can only be iterated once unlike sorted(), etc... Script to illustrate the issue: /tmp/rev: orig = [ 'x', 'a', 'y', 'b', 'z', 'c' ] co = sum( 1 for _ in orig ) print( 'orig', orig, co ) # reversing rev = reversed(orig) print( 'before iteration:', [ x for x in rev ] ) # list comprehension was an iteration over 'rev' print( 'after iteration:', [ x for x in rev ] ) # how this was discovered... orig = [ 'x', 'a', 'y', 'b', 'z', 'c' ] rev = reversed(orig) cr = sum( 1 for _ in rev ) print( 'after sum():', [ x for x in rev ] ) which produces: $ python /tmp/rev orig ['x', 'a', 'y', 'b', 'z', 'c'] 6 before iteration: ['c', 'z', 'b', 'y', 'a', 'x'] after iteration: [] after sum(): [] Regards, Pierre -- https://mail.python.org/mailman/listinfo/python-list
[Python-announce] CodraFT 2.1.2 has been released
Hi all, CodraFT is an open-source generic signal and image processing software, based on Python, Qt, NumPy, SciPy and others: https://codra-ingenierie-informatique.github.io/CodraFT/ I am pleased to announce that CodraFT v2.1.2 has been released. This is a hotfix release, following the v2.1 major release (june 2022). CodraFT provides signal/image processing and visualisation features, and is available either as a stand-alone application or may be embedded in your own Python-Qt application thanks to advanced automation capabilities. CodraFT also has many I/O features, supporting a lot of images format as well as HDF5 (for saving/loading CodraFT workspace or importing any other data file). Enjoy! -- Always a pleasure to share with Python community, since 2008. Pierre Raybaut ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com
[Python-announce] CodraFT v2.1.1
Hi all, CodraFT is an open-source generic signal and image processing software, based on Python, Qt, NumPy, SciPy and others: https://codra-ingenierie-informatique.github.io/CodraFT/ I am pleased to announce that CodraFT v2.1.1 has been released. This is the second public release of version 2, compatible with Python 3.7+. CodraFT provides signal/image processing and visualisation features, and is available either as a stand-alone application or may be embedded in your own Python-Qt application thanks to advanced automation capabilities. CodraFT also has many I/O features, supporting a lot of images format as well as HDF5 (for saving/loading CodraFT workspace or importing any other data file). Enjoy! -- Always a pleasure to share with Python community, since 2008. Pierre Raybaut ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com
[Python-announce] CodraFT v2.0.2
Hi all, CodraFT is a new open-source generic signal and image processing software, based on Python, Qt, NumPy, SciPy and others: https://codra-ingenierie-informatique.github.io/CodraFT/ I am pleased to announce that CodraFT v2.0.2 has been released. This is the first public release of version 2, compatible with Python 3.7+. CodraFT provides signal/image processing and visualisation features, and is available either as a stand-alone application or may be embedded in your own Python-Qt application thanks to advanced automation capabilities. CodraFT also has many I/O features, supporting a lot of images format as well as HDF5 (for saving/loading CodraFT workspace or importing any other data file). Enjoy! -- Always a pleasure to share with Python community, since 2008. Pierre Raybaut ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com
[issue47259] string sorting often incorrect
New submission from Pierre Ossman : There is a big gotcha in Python that is easily overlooked and should at the very least be more prominently pointed out in the documentation. Sorting strings will produce results that is very confusing for humans. I happens to work for ASCII, but will generally produce bad results for other things as code points do not always follow the alphabetical order. The expressions chapter¹ mentions this fact, but you have to dig quite a bit to reach that. It also mentions that normalization is an issue, but it never mentions the issue about code point order versus alphabetical order. The sorting tutorial mentions under "Odds and ends"² that you need to use a special key or comparison function to get locale aware sorting. It doesn't mention that this also includes respecting alphabetical order, which might be overlooked unless you are very familiar with how the sorting works. The tutorial is also something you have to dig a bit to reach. Ideally string comparison would always be locale aware in a high level language such as Python. However, a smaller step would be a note on sorted()³ that extra care needs to be taken for strings as the default behaviour will produce unexpected results once your strings include anything outside the English alphabet. ¹ https://docs.python.org/3/reference/expressions.html ² https://docs.python.org/3/howto/sorting.html#odd-and-ends ³ https://docs.python.org/3/library/functions.html#sorted -- components: Interpreter Core messages: 416972 nosy: CendioOssman priority: normal severity: normal status: open title: string sorting often incorrect ___ Python tracker <https://bugs.python.org/issue47259> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46767] [Doc] sqlite3 Cursor.execute() return value is unspecified
New submission from Pierre Thierry : In the documentation of the sqlite3 module, the return value for Connection.execute() is told to be the Cursor that was implicitly created, but nothing is said about the return value/type when using Cursor.execute(). -- components: Library (Lib) messages: 413327 nosy: kephas priority: normal severity: normal status: open title: [Doc] sqlite3 Cursor.execute() return value is unspecified type: enhancement versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue46767> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46302] IndexError inside list comprehension + workaround
Pierre Fortin added the comment: [Thanks for the replies! I was trying to post this before seeing them.] Major egg on face... The more complex the code becomes, the more likely you will be burned by a rookie mistake... var = '' var[0] WILL give IndexError -- Duh! It was buried in the each.split('=') returning an empty string -- that's what you get for making things easier for the user. The easier code is to use, the more complex it must be... Sorry for the noise. -- ___ Python tracker <https://bugs.python.org/issue46302> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46302] IndexError inside list comprehension + workaround
New submission from Pierre Fortin : var = "u2" var.strip()[0] Works as expected, except that it returns IndexError (instead of "u") if used in a list comprehension -- at least, that's where I found it. Attached example script illustrates the issue. Call it with "mytest N" where N is 1 (fails), 2 (works), 3 (fails). mytest 1 -- KeyError expected; this was due to infile design change adding a digit to previously single char code mytest 2 -- workaround to actual issue in next test mytest 3 -- adding [0] fails when used in list comprehension -- components: Interpreter Core files: mytest messages: 410054 nosy: NetAlien priority: normal severity: normal status: open title: IndexError inside list comprehension + workaround type: behavior versions: Python 3.8 Added file: https://bugs.python.org/file50548/mytest ___ Python tracker <https://bugs.python.org/issue46302> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45807] Strange SyntaxError message / suggestions for "@x = 123"
New submission from Pierre Quentel : In CPython 3.10 : Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> @x = 123 File "", line 1 @x = 123 ^^^ SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='? but both suggestions lead to a SyntaxError : >>> @x == 123 ... File "", line 2 ^ SyntaxError: invalid syntax >>> @x := 123 ... File "", line 2 ^ SyntaxError: invalid syntax >>> Maybe an error message such as "cannot assign to decorator" would be more appropriate ? -- components: Parser messages: 406351 nosy: lys.nikolaou, pablogsal, quentel priority: normal severity: normal status: open title: Strange SyntaxError message / suggestions for "@x = 123" type: enhancement versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue45807> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44774] incorrect sys.stdout.encoding within a io.StringIO buffer
Pierre Carbonnelle added the comment: I can live with the workaround, so, you can close the issue if you wish. As you say, maybe it's an issue with z3. Thank you for your time. -- ___ Python tracker <https://bugs.python.org/issue44774> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44774] incorrect sys.stdout.encoding within a io.StringIO buffer
Pierre Carbonnelle added the comment: As a work around, I had to use a temporary file (instead of a memory buffer): print("outside:", sys.stdout.encoding) with open("/tmp/log.txt", mode='w', encoding='utf-8') as buf: with redirect_stdout(buf) as f: print("inside: ", sys.stdout.encoding) with open("/tmp/log.txt", mode='r', encoding='utf-8') as f: print(f.read()) and get: outside: utf-8 inside: utf-8 as expected. -- ___ Python tracker <https://bugs.python.org/issue44774> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44774] incorrect sys.stdout.encoding within a io.StringIO buffer
Pierre Carbonnelle added the comment: I expect sys.stdout to have utf-8 encoding inside the redirect because the buffer accepts unicode code points (not bytes), just as it does outside of the redirect. In other words, I expect the 'encoding' attribute of sys.stdout to have the same value inside and outside this redirect. It so happens that sys.stdout is an io.StringIO() object inside the redirect. The getvalue() method on this object returns a string (not a bytes), i.e. a sequence of unicode points. StringIO inherits from TextIOBase, which has an 'encoding' attribute. For some reason, the encoding of a StringIO object is None, which is inconsistent with its semantics: it should be 'uft-8'. -- ___ Python tracker <https://bugs.python.org/issue44774> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44774] incorrect sys.stdout.encoding within a io.StringIO buffer
New submission from Pierre Carbonnelle : The following code print("outside:", sys.stdout.encoding) with redirect_stdout(io.StringIO()) as f: print("inside: ", sys.stdout.encoding) print(f.getvalue()) yields: outside: utf-8 inside: None Because StringIO is a string buffer, the expected result is: outside: utf-8 inside: utf-8 This creates problem when using packages whose output depends on the sys.stdout.encoding, such as z3-solver. -- components: Library (Lib) messages: 398528 nosy: pcarbonn priority: normal severity: normal status: open title: incorrect sys.stdout.encoding within a io.StringIO buffer type: behavior versions: Python 3.9 ___ Python tracker <https://bugs.python.org/issue44774> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44741] Pattern Matching - star subpattern with a subject derived from collections.abc.Sequence
Pierre Quentel added the comment: I found why len() is required, it's to avoid trying to match the subject (thus consuming a part of it) if its length is less than the number of non-star patterns, as explained in the PEP. My mistake, sorry. -- ___ Python tracker <https://bugs.python.org/issue44741> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44741] Pattern Matching - star subpattern with a subject derived from collections.abc.Sequence
Pierre Quentel added the comment: Oh, I did not invent this class, it is in the test script for pattern matching : https://github.com/python/cpython/blob/6948964ecf94e858448dd28eea634317226d2913/Lib/test/test_patma.py#L1932 With this class, [x, *_, y] matches, but not [x, *w, y] : this is what made me create this issue. Maybe it would be a good idea to change this class in test_patma.py ? OTOH, if the current implementation remains the same, why does the PEP insist on subjects having a len() ? Could sequence patterns match a wider range of subjects that can be unpacked ? -- ___ Python tracker <https://bugs.python.org/issue44741> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44741] Pattern Matching - star subpattern with a subject derived from collections.abc.Sequence
Pierre Quentel added the comment: Thanks for the explanations, but I feel unconfortable with the fact that variable-length sequence patterns are implemented the same as unpacking. (sorry if this has been discussed before, I can't find references to the discussions that lead to the current version of the PEP). There are obvious similarities between [x, *y, z] = A and match A: case [x, *y, z]: print('ok') but a big difference, put forward in PEP 634 : the classes supported for pattern matching are limited (unpacking a generator expression is possible, but they are not supported as subjects for sequence patterns), and the PEP explicitely refers to them having a len(). It seems to me that this implies that the algorithms should be different: - for unpacking, the iterable must be completely consumed before binding the names on the left-hand side. If it is infinite, unpacking fails - for variable-length sequence pattern matching (this is how I understand the last paragraph about them in PEP 634): . get the subject length . iterate one by one before the star pattern . iterate (len(subject) - number of non-star patterns) times for the star pattern . iterate one by one after the star pattern In the second case, even if the subject never raises StopIteration, the match succeeds. Does this make sense ? -- ___ Python tracker <https://bugs.python.org/issue44741> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44741] Pattern Matching - star subpattern with a subject derived from collections.abc.Sequence
New submission from Pierre Quentel : This code match range(42): case [x, *w, y]: z = 0 sets w to a list with 40 items : the length of the subject, minus the number of non-star subpatterns. But this code (adapted from test_patma_186) enters an infinite loop import collections.abc class Seq(collections.abc.Sequence): def __getitem__(self, i): print('get item', i) return i def __len__(self): return 42 match Seq(): case [x, *w, y]: z = 0 __getitem__ gets called forever, instead of stopping when the expected number of items in w is reached. -- components: Interpreter Core messages: 398226 nosy: quentel priority: normal severity: normal status: open title: Pattern Matching - star subpattern with a subject derived from collections.abc.Sequence type: crash versions: Python 3.10, Python 3.11 ___ Python tracker <https://bugs.python.org/issue44741> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44589] Pattern Matching - duplicate keys in mapping patterns
Pierre Quentel added the comment: Sorry, I don't know C so I can't write a PR for this change. -- ___ Python tracker <https://bugs.python.org/issue44589> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44589] Pattern Matching - duplicate keys in mapping patterns
New submission from Pierre Quentel : PEP 634 specifies that "A mapping pattern may not contain duplicate key values. (If all key patterns are literal patterns this is considered a syntax error; otherwise this is a runtime error and will raise ValueError.)" but this is not what happens with the latest release: Python 3.10.0b3 (tags/v3.10.0b3:865714a, Jun 17 2021, 20:39:25) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> x = {'a': 1} >>> match x: ... case {'a': 1, 'a': 2}: # (A) ... print('ok') ... >>> x = {'a': 3} >>> match x: ... case {'a': 1, 'a': 2}: # (B) ... print('ok') ... >>> x = {'a': 1, 'b': 2} >>> match x: ... case {'a': 1, 'a': 2}: # (C) ... print('ok') ... Traceback (most recent call last): File "", line 2, in ValueError: mapping pattern checks duplicate key ('a') >>> If I understand the PEP correctly, all these examples should raise a SyntaxError for the line case {'a': 1, 'a': 2}: since all key patterns are literal patterns, and the key 'a' is duplicated. Cases (A) where the subject matches one of the key-value patterns, and (B) when it doesn't, fail without raising SyntaxError. Case (C) where one of the keys in the subject is not present in the mapping pattern raises a ValueError at runtime instead of SyntaxError. This behaviour is tested in test_patma.py: def test_patma_251(self): x = {"a": 0, "b": 1} w = y = z = None with self.assertRaises(ValueError): match x: case {"a": y, "a": z}: w = 0 self.assertIs(w, None) self.assertIs(y, None) self.assertIs(z, None) but this doesn't seem compliant with the specification. BTW, it's not clear to me why the SyntaxError should be limited to the case when all keys are literal patterns; it could be raised whenever a literal pattern is repeated, even when there are value patterns or a double-star pattern, like in case {'a': 1, 'a': 2, c.imag, **rest}: -- components: Interpreter Core messages: 397195 nosy: quentel priority: normal severity: normal status: open title: Pattern Matching - duplicate keys in mapping patterns versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue44589> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44503] Hide __enter__ calls in mock_open
Pierre Ossman added the comment: Also see Issue44185 for __exit__. -- ___ Python tracker <https://bugs.python.org/issue44503> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44503] Hide __enter__ calls in mock_open
New submission from Pierre Ossman : I'd like to write this test case: with patch('builtins.open') as pyopen: mock_open(pyopen, read_data="foo") run() pyopen.assert_has_calls([call("filename", "wt"), call().write("gazonk"), call().close()]) and I shouldn't have to care if the code is written like this: def run(): f = open("filename", "wt") try: write("gazonk") finally: f.close() or like this: def run(): with open("filename", "wt") as f: write("gazonk") -- components: Library (Lib) messages: 396469 nosy: CendioOssman priority: normal severity: normal status: open title: Hide __enter__ calls in mock_open type: enhancement ___ Python tracker <https://bugs.python.org/issue44503> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44185] mock_open file handle __exit__ does not call close
Change by Pierre Ossman : -- nosy: +CendioOssman ___ Python tracker <https://bugs.python.org/issue44185> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue512981] readline /dev/tty problem
Pierre added the comment: A workaround consists in replacing fd(0) with /dev/tty without modifying sys.stdin import os stdin = os.dup(0) os.close(0) tty = os.open("/dev/tty", os.O_RDONLY) assert tty == 0 import readline print("input:", input()) print("in:", os.read(stdin, 128)) -- ___ Python tracker <https://bugs.python.org/issue512981> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue512981] readline /dev/tty problem
Pierre added the comment: Please, let me know if I should re-open a new bug for this one. -- ___ Python tracker <https://bugs.python.org/issue512981> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44085] Remaining invalid rules in simplified grammar
New submission from Pierre Quentel : In the simplified version of Python grammar at https://docs.python.org/3.10/reference/grammar.html, most 'invalid_' from the complete grammar at https://github.com/python/cpython/blob/3.10/Grammar/python.gram have been removed, but 2 of them remain : primary: | invalid_primary # must be before 'primay genexp' because of invalid_genexp dict: | '{' invalid_double_starred_kvpairs '}' I suppose that the simplified version is extracted from the complete grammar with a program, and this program doesn't detect the 'invalid_' that don't end the line, since these 2 occurrences correspond to the only such lines in the complete grammar primary[expr_ty]: | invalid_primary # must be before 'primay genexp' because of invalid_genexp dict[expr_ty]: | '{' invalid_double_starred_kvpairs '}' Also note the typo in the comment : 'primay genexp' instead of 'primary genexp' -- assignee: docs@python components: Documentation messages: 393306 nosy: docs@python, quentel priority: normal severity: normal status: open title: Remaining invalid rules in simplified grammar versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue44085> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44052] patch object as argument should be explicit
Pierre Ossman added the comment: I've always been cautious about running patch() manually since it was easy to miss the cleanup. But those fears might be irrelevant these days when we have addCleanup(). Still, decorators are a more robust in more complex setups since you don't have to worry about setUp() being properly called in every base class. So I still think this would be interesting. A different function might be an option to avoid adding arguments. Just like there are a few special patch.*() already. -- ___ Python tracker <https://bugs.python.org/issue44052> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44052] patch object as argument should be explicit
New submission from Pierre Ossman : Right now if you use unittest.mock.patch() as a decorator it may or may not pass the object as an argument to the test function. The behaviour is a side effect of the argument "new" rather than something the caller can explicitly control. In many cases this gives the desired behaviour, but not in all. So this behaviour should be possible to explicitly controlled. One common case is when using patch() as a class decorator. If you want to avoid getting extra arguments to every test function, then "new" has to be specified. But that means that it will be the same object that will be used for every test, not a fresh one. E.g. @patch('foo.bar.baz', []) class TestCases(unittest.TestCase): def test_a(self): ... def test_b(self): ... def test_c(self): ... The tests will now be running with the same list in "foo.bar.baz" rather than a fresh empty list for each run. Ideally we could instead specify: @patch('foo.bar.baz', new_callable=list, as_arg=False) class TestCases(unittest.TestCase): def test_a(self): ... def test_b(self): ... def test_c(self): ... Or something along those lines. -- components: Library (Lib) messages: 393062 nosy: CendioOssman priority: normal severity: normal status: open title: patch object as argument should be explicit ___ Python tracker <https://bugs.python.org/issue44052> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue512981] readline /dev/tty problem
Pierre added the comment: I suggest to reopen this issue as there was a regression with python3. import sys sys.stdin = open("/dev/tty", "r") import readline print(input()) Write some text and press left. Expected: the cursor goes left. Actual: prints '^[[D' as is readline had not been imported. bltinmodule.c checks that the current sys.stdin filno matches the C stdin fileno. When they are different, it falls back to the default input implementation. https://github.com/python/cpython/blob/1e7b858575d0ad782939f86aae4a2fa1c29e9f14/Python/bltinmodule.c#L2097 I noticed that PyFile_AsFile no longer exists. Would calling `fdopen` be acceptable? -- nosy: +pierre.labatut type: -> behavior versions: +Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue512981> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42916] Support for DICOM image file format in imghdr module
Pierre-Alain Moret added the comment: The DICOM format is indeed very widely used in the medical field and for me it deserves to be added in stdlib. I do not see why it is more specific than rast format which is included. Moreover it should be easy to add because even if the complete format is very complex with all the medical modalities, its enough to test the first 132 bytes of image that should be: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00DICM' Of course, its not enough to test that we have a valid DICOM image, but it is also not the case with other formats. For example, with this simple corrupted jpeg image : imghdr.what('dummy', h= b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\xff\xd9') 'jpeg' is returned. That is why I strongly advocate in favor of adding DICOM format in imghdr. Pierre-Alain Moret -- nosy: +pam ___ Python tracker <https://bugs.python.org/issue42916> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42833] Lib/urllib/request.py: digest algorithm should be case insensitive
Change by Pierre Tardy : -- pull_requests: +22953 status: pending -> open pull_request: https://github.com/python/cpython/pull/24122 ___ Python tracker <https://bugs.python.org/issue42833> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42833] Lib/urllib/request.py: digest algorithm should be case insensitive
New submission from Pierre Tardy : original bug report: https://github.com/buildbot/buildbot/issues/5743 Twisted by default advertises its algorithm in lowercase, which is uncommon, but allowed by the spec. https://tools.ietf.org/html/rfc3230#section-4.1.1 python's request.py is only supporting MD5 or SHA as algorithm, and not lowercase equivalent. This is an easy and harmless fix. -- messages: 384409 nosy: Pierre.Tardy priority: normal severity: normal status: open title: Lib/urllib/request.py: digest algorithm should be case insensitive type: behavior versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue42833> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42833] Lib/urllib/request.py: digest algorithm should be case insensitive
Change by Pierre Tardy : -- components: +Library (Lib) status: open -> pending ___ Python tracker <https://bugs.python.org/issue42833> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41915] unittest.mock.create_autospec(Obj, instance=True) has self keyword in _spec_signature if Obj implements __call__
Pierre Ossman added the comment: autospec's behaviour for methods is currently needed to work around Issue42556, so be careful with any fixes here so they don't break that workaround. -- nosy: +CendioOssman ___ Python tracker <https://bugs.python.org/issue41915> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42556] unittest.mock.patch() cannot properly mock methods
New submission from Pierre Ossman : unittest.mock.patch() as it currently works cannot properly mock a method as it currently replaces it with something more mimicking a function. I.e. the descriptor magic that includes "self" isn't properly set up. In most cases this doesn't really matter, but there are a few use cases where this is important: 1. Calling base classes where you need to make sure it works regardless of super() or direct reference to the base class. 2. Multiple objects calling the same base class using super(). Without the self argument you can't tell the calls apart. 3. Setting up a side_effect that needs access to the object. In some cases you can pass the object using some side channel, but not all. E.g. not when mocking a base class' __init__(). (already reported as Issue35577). Right now you can work around this by using autospec, as that has the undocumented side-effect of properly setting up methods. So don't fix Issue41915 before this one or we lose that workaround. :) -- components: Library (Lib) messages: 382415 nosy: CendioOssman priority: normal severity: normal status: open title: unittest.mock.patch() cannot properly mock methods versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue42556> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42320] unexpected difference between map and list
Pierre van de Laar added the comment: Not a bug: tuple is an iterator but an iterator is not a tuple. Yet iterators are often accepted during initialization... -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue42320> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42320] unexpected difference between map and list
Pierre van de Laar added the comment: Zip didn't contain the test cases from the tests directory (sorry for that) -- Added file: https://bugs.python.org/file49592/tests.zip ___ Python tracker <https://bugs.python.org/issue42320> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42320] unexpected difference between map and list
New submission from Pierre van de Laar : On windows, with python 3.9, with unittests, My test case fails when I use the following lines of code ``` result = map(lambda x: self.substitute_in_expression(x), sequence.sequence) ``` It works fine with ``` result = list() for x in sequence.sequence: result.append(self.substitute_in_expression(x)) ``` Note that result is used as input for an inherited class instantiation: ``` sequence_type = type(sequence) return sequence_type(result) ``` The classes are constructed using the dataclass decorator! I have unfortunately not have time to make a small reproducer. So I just send the whole project. -- files: bug.zip messages: 380742 nosy: Pierre van de Laar priority: normal severity: normal status: open title: unexpected difference between map and list type: behavior versions: Python 3.9 Added file: https://bugs.python.org/file49591/bug.zip ___ Python tracker <https://bugs.python.org/issue42320> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Interference tkinter and plot from matplotlib
Thank you, Mr. Gollwitzer. I understand the problem. I'll see what I can do. Regards, P.Bonville Le mer. 30 sept. 2020 à 17:02, Christian Gollwitzer a écrit : > Am 30.09.20 um 15:46 schrieb Pierre Bonville: > > Hi everybody, > > > Interference tkinter and plot from matplotlib > > > You are mixing different ways of control flow. In a GUI program, don't > call input(). Use the mainloop() as the very last of your calls, and > only work in the callbacks. That means you would integrate a "Next" > button in your GUI which switches the plots - or even show them side by > side. > > Concerning matplotlib, you'll need to tell it to integrate with Tk > properly. > > https://matplotlib.org/3.3.1/gallery/user_interfaces/embedding_in_tk_sgskip.html > > > If you want a simple solution instead of full-blown GUI programming, use > IPython https://ipython.readthedocs.io/en/stable/config/eventloops.html > or jupyter notebooks. > > > Christian > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Interference tkinter and plot from matplotlib
Hi everybody, I am running this little program below on Win 10 with Python 3.8 (just typing prog.py after the prompt c:\Users ...>), and while it correctly displays the window and does the first plt.plot(), it does not reach the input command and remains waiting after I shut the plot. If I replace 'quit' by 'destroy' in the button command, it works correctly. I looked on various Python forums on the Net, but didn't find an answer. Regards, P.Bonville import tkinter as tk import matplotlib.pyplot as plt r = tk.Tk() b = tk.Button(r, text= r.quit) b = tk.Button(r, text='quit', command=r.quit) b.pack() r.mainloop() # This blocks until press button. # Root window with button is still displayed. plt.plot() plt.show() rep = input("Return") plt.plot() plt.show() -- https://mail.python.org/mailman/listinfo/python-list
tkinter and input()
Hello everybody, I have a small problem with the method .quit() of tkinter. Below is a sketch of a much larger program, which shows the problem. I would like to run the main program but keeping the tk window on the screen until the end. Presently, execution stops after the first "plot" instruction. I don't understand why. The program runs fine if one replaces "quit" by "destroy", but then the tk window disappears. Is there a solution? Thanks in advance for any answer, Regards, P.Bonville # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import numpy as np from tkinter import * def init(): global vit def print_par(): global vitt vitt = vit.get() print("velocity= ",vitt," cm/s") fen.quit() vit = "" fen = Tk() vit0 = StringVar() Label(fen, text = "velocity (cm/s): ").grid(row=0) vit = Entry(fen,text = vit0) vit0.set(7.) vit.grid(row=0, column=1) button = Button(fen, text='OK', command=print_par).grid(row=5,column=0) fen.mainloop() vit = float(vitt) init() print(vit) x = np.arange(0,4*np.pi,0.1) y = np.sin(x) for i in range(0,10): plt.plot(x,y) plt.show() re = input("Hit RETURN to continue:") -- https://mail.python.org/mailman/listinfo/python-list
ANN: PythonQwt 0.6.2
Hi all, I am pleased to announce that PythonQwt v0.6.2 has been released (https://github.com/PierreRaybaut/PythonQwt). This is a maintenance release, compatible with Python 2.7, 3.4-3.8, PyQt4 and PyQt5. The PythonQwt package is a 2D-data plotting library using Qt graphical user interfaces for the Python programming language. It is compatible with both PyQt4 and PyQt5 (PySide is currently not supported but it could be in the near future). The PythonQwt project was initiated to solve -at least temporarily (at the time...)- the obsolescence issue of PyQwt (the Python-Qwt C++ bindings library) which is no longer maintained. The idea was to translate the original Qwt C++ code to Python and then to optimize some parts of the code by writing new modules based on NumPy and other libraries. The PythonQwt package consists of a single Python package named qwt which is a pure Python implementation of Qwt C++ library with some limitations: efforts were concentrated on basic plotting features, leaving higher level features to the guiqwt library. The PythonQwt documentation with examples, API reference, etc. is available here: https://pythonqwt.readthedocs.io/en/latest/ Python package index page: https://pypi.org/project/PythonQwt/ -- Pierre Raybaut ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com
ANN: guidata v1.7.7
Hi all, I am pleased to announce that `guidata` v1.7.7 has been released (https://github.com/PierreRaybaut/guidata). This is a maintenance release with a couple of bugfixes (compatibility with Spyder v4) -- guidata is compatible with Python 2.7, 3.4-3.8, PyQt4 and PyQt5. Based on the Qt GUI library (PyQt4, PyQt5, and mostly compatible with PySide), guidata is a Python library generating graphical user interfaces for easy dataset editing and display. It also provides helpers and application development tools for PyQt. guidata also provides the following features: * guidata.qthelpers: PyQt helpers * guidata.disthelpers: cx_Freeze/py2exe helpers (or how to build a self-consistent executable in three lines of code!) * guidata.userconfig: .ini configuration management helpers (based on Python standard module ConfigParser) * guidata.configtools: library/application data management * guidata.gettext_helpers: translation helpers (based on the GNU tool gettext) * guidata.guitest: automatic GUI-based test launcher * guidata.utils: miscelleneous utilities guidata has been successfully tested on GNU/Linux and Windows platforms. The `guidata` documentation with examples, API reference, etc. is available here: https://guidata.readthedocs.io/en/latest/ Python package index page: http://pypi.python.org/pypi/guidata/ -- Pierre Raybaut ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com
[issue39492] reference cycle affecting Pickler instances (Python3.8+)
Change by Pierre Glaser : -- keywords: +patch pull_requests: +17643 stage: -> patch review pull_request: https://github.com/python/cpython/pull/18266 ___ Python tracker <https://bugs.python.org/issue39492> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39492] reference cycle affecting Pickler instances (Python3.8+)
New submission from Pierre Glaser : The new Pickler reducer_override mechanism introduced in `Python3.8` generates a reference cycle: for optimization purposes, a the pickler.reducer_override bound method is referenced into the reducer_override attribute of the Pickler's struct. Thus, until as a gc.collect call is performed, both the Pickler and all the elements it pickled (as they are part of its memo), wont be collected. We should break this cycle a the end of the dump() method. See reproducer below: ``` import threading import weakref import pickle import io class MyClass: pass my_object = MyClass() collect = threading.Event() _ = weakref.ref(my_object, lambda obj: collect.set()) # noqa class MyPickler(pickle.Pickler): def reducer_override(self, obj): return NotImplemented my_pickler = MyPickler(io.BytesIO()) my_pickler.dump(my_object) del my_object del my_pickler # import gc # gc.collect() for i in range(5): collected = collect.wait(timeout=0.1) if collected: print('my_object was successfully collected') break ``` -- components: Library (Lib) messages: 360995 nosy: pierreglaser, pitrou priority: normal severity: normal status: open title: reference cycle affecting Pickler instances (Python3.8+) type: resource usage versions: Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue39492> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32371] Delay-loading of python dll is impossible when using some C macros
Change by Pierre Chatelier : -- versions: +Python 3.8 -Python 3.6 ___ Python tracker <https://bugs.python.org/issue32371> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32371] Delay-loading of python dll is impossible when using some C macros
Pierre Chatelier added the comment: Aaand finally there is still something : it depends on the call context. Once in a C++/CLI class, the link bug occurs again. Here is attached a minimal project. -- status: closed -> open Added file: https://bugs.python.org/file48721/PythonFromC.zip ___ Python tracker <https://bugs.python.org/issue32371> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32371] Delay-loading of python dll is impossible when using some C macros
Pierre Chatelier added the comment: Just reproduced and solved it at the same time ! It happened with Debug build, where I linked to pythonxx.lib instead of pythonxx_d.lib, because I did not download the debug binaries. Ultimately : my fault. -- ___ Python tracker <https://bugs.python.org/issue32371> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32371] Delay-loading of python dll is impossible when using some C macros
Pierre Chatelier added the comment: Can't reproduce any more. It might have been specific to the Visual Studio version I used at that time. -- ___ Python tracker <https://bugs.python.org/issue32371> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38469] PEP 572 : assignment expression to a global variable in a comprehension
Pierre Quentel added the comment: That was a quick fix, thanks ! -- ___ Python tracker <https://bugs.python.org/issue38469> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38469] PEP 572 : assignment expression to a global variable in a comprehension
New submission from Pierre Quentel : PEP 572 says that "an assignment expression occurring in a (...) comprehension (...) binds the target in the containing scope, honoring a nonlocal or global declaration for the target in that scope, if one exists." In Appendix B, the PEP shows this example : def f(): global TARGET a = [TARGET := EXPR for VAR in ITERABLE] So I don't understand why this fails: Python 3.8.0rc1 (tags/v3.8.0rc1:34214de, Oct 1 2019, 18:42:37) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> x = 0 >>> def f(): ... global x ... [x := i for i in range(5)] ... File "", line 3 SyntaxError: no binding for nonlocal 'x' found >>> Is this a bug or am I missing something ? -- components: Interpreter Core messages: 354601 nosy: quentel priority: normal severity: normal status: open title: PEP 572 : assignment expression to a global variable in a comprehension type: behavior versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue38469> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20504] cgi.FieldStorage, multipart, missing Content-Length
Pierre Quentel added the comment: Now that the PR has been merged, can someone close the issue ? -- ___ Python tracker <https://bugs.python.org/issue20504> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21705] cgi.py: Multipart with more than one file is misparsed
Pierre Quentel added the comment: @ethan.furman Yes, in test_cgi.py, the method test_fieldstorage_multipart_w3c https://github.com/python/cpython/blob/master/Lib/test/test_cgi.py#L316) uses a multipart content with 2 files in it (https://github.com/python/cpython/blob/master/Lib/test/test_cgi.py#L579) -- ___ Python tracker <https://bugs.python.org/issue21705> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37921] Improve zipfile: add support for symlinks
Pierre-Jean Grenier added the comment: The PR went through review and has been awaiting core review for almost a month, anyone to have a look at it? :) -- ___ Python tracker <https://bugs.python.org/issue37921> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21705] cgi.py: Multipart with more than one file is misparsed
Pierre Quentel added the comment: The patch has been applied some time ago (I couldn't find the exact commit), cf. https://github.com/python/cpython/blob/master/Lib/cgi.py#L750 I think we can close the issue. -- nosy: +quentel ___ Python tracker <https://bugs.python.org/issue21705> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38092] environment variables not passed correctly using new virtualenv launching in windows and python3.7+
Change by Pierre Glaser : -- keywords: +patch pull_requests: +15524 stage: -> patch review pull_request: https://github.com/python/cpython/pull/15883 ___ Python tracker <https://bugs.python.org/issue38092> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38082] datetime.time object incorrectly shows associated date in strftime() output
Change by Pierre Glaser : -- pull_requests: +15523 pull_request: https://github.com/python/cpython/pull/15882 ___ Python tracker <https://bugs.python.org/issue38082> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38092] environment variables not passed correctly using new virtualenv launching in windows and python3.7+
Pierre Glaser added the comment: > Dropping this into Lib/multiprocessing/spawn.py should cause a repro: if WINSERVICE: _python_exe = os.path.join(sys.exec_prefix, 'python.exe') else: _python_exe = getattr(sys, '_base_executable', sys.executable) In this case, spawn.get_executable() will return (sys._base_executable), and `env` will be set to None anyways no? (see these lines: https://github.com/python/cpython/blob/9008be303a89bfab8c3314c6a42330b5523adc8b/Lib/multiprocessing/popen_spawn_win32.py#L59-L68) We need to trigger the if clause of these lines instead, which happens by default in a virtual env -- this is why it is so troubling: even though a very simple case (launching a new process from within a virtualenv) should trigger a bug, it does not. > And maybe submit a PR with the fix? Will do. -- ___ Python tracker <https://bugs.python.org/issue38092> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38092] environment variables not passed correctly using new virtualenv launching in windows and python3.7+
New submission from Pierre Glaser : If I am not mistaken, when creating a new process on Python3.7 and later on Windows, if using a virtualenv, Python now uses a launcher. The launcher is being notified that it must create a virtual-environment Python (and not a system Python) program using the __PYVENV_LAUNCHER__ environment variable, passed as part of the environment of launcher process created using in _winapi.CreateProcess (see https://github.com/python/cpython/blob/9008be303a89bfab8c3314c6a42330b5523adc8b/Lib/multiprocessing/popen_spawn_win32.py#L73-L75) However, if I am not mistaken `env` is not passed at the right position (https://github.com/python/cpython/blob/9008be303a89bfab8c3314c6a42330b5523adc8b/Modules/_winapi.c#L1062-L1068). These lines were part of a bugfix patch (see https://bugs.python.org/issue35797), solving an issue for multiprocessing-based packages. We ended trying to backport to loky (https://github.com/tomMoral/loky, a multiprocessing-based package) but the bug was not fixed. Passing 'env' correctly fixed the bug. Two things: - It is hard to provide a reproducer for this issue as it requires patching the CPython source code. - I don't understand why env being not passed correctly does not manifest itself in the test-suite. What is even more troubling is that even with this bug, the virtualenv launcher seems to get that a virtualenv is used when creating processes in multiprocessing (at least, sys.path includes the path/to/venv/lib/python3.x/site-packages). However, I am not familiar with the virtualenv launcher for python3.7+ and windows. -- components: Windows messages: 351650 nosy: paul.moore, pierreglaser, pitrou, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: environment variables not passed correctly using new virtualenv launching in windows and python3.7+ type: crash versions: Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue38092> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37921] Improve zipfile: add support for symlinks
Change by Pierre-Jean Grenier : -- keywords: +patch pull_requests: +15108 stage: -> patch review pull_request: https://github.com/python/cpython/pull/15401 ___ Python tracker <https://bugs.python.org/issue37921> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37921] Improve zipfile: add support for symlinks
New submission from Pierre-Jean Grenier : The module tarfile contains some methods for knowing whether an archive member is a regular file/a directory/a symlink. Apart from an "is_dir()" method, there was nothing alike in the zipfile module. For an on-going project, I needed to know whether an archive member was a symlink or not, to prevent zip symlinks attacks. I thought this could be of used for other people, given I struggled a little to find a way of saying if an archive member is a symlink or not. This is why I think adding support for symlinks in the zipfile module could be a good idea. -- components: Library (Lib) messages: 350231 nosy: zaphodef priority: normal severity: normal status: open title: Improve zipfile: add support for symlinks type: enhancement versions: Python 3.9 ___ Python tracker <https://bugs.python.org/issue37921> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue28053] parameterize what serialization is used in multiprocessing
Change by Pierre Glaser : -- pull_requests: +14807 pull_request: https://github.com/python/cpython/pull/15058 ___ Python tracker <https://bugs.python.org/issue28053> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37652] Multiprocessing shared_memory ValueError on race with ShareableList
Pierre Glaser added the comment: Sure, although I won't be able to merge it. Make sure you ping a core-dev such as pitrou or davin :-) -- ___ Python tracker <https://bugs.python.org/issue37652> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37652] Multiprocessing shared_memory ValueError on race with ShareableList
Pierre Glaser added the comment: The root of the error is that struct.pack_into starts by memsetting the underlying memory area with NULL bytes before filling the data with memcpy. If ShareableList._get_packing_format is called between the two operations (through a concurrent __getitem__ call from another process), struct.unpack_from will return an empty tuple which is the direct cause of the error you're seeing. In the general case though, memcpy is not atomic so even without the memset call before, results of struct.unpack_from may be invalid in a concurrent setting. shared_memory is a low level python module. Precautions should be made when handling concurrently the shared_memory objects using synchronization primitives for example. I'm not sure this should be done internally in the SharedMemory class -- especially, we don't want to slow down concurrent READ access. +1 For a documentation addition. -- ___ Python tracker <https://bugs.python.org/issue37652> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16512] imghdr doesn't recognize variant jpeg formats
Change by Pierre Chopin : -- pull_requests: +14651 pull_request: https://github.com/python/cpython/pull/14862 ___ Python tracker <https://bugs.python.org/issue16512> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37629] Imghdr doesnt recognise some jpeg
Pierre Chopin added the comment: This is actually a duplicate of bpo-16512, i am closing this. -- resolution: -> duplicate stage: -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue37629> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37629] Imghdr doesnt recognise some jpeg
New submission from Pierre Chopin : the imghdr library only checks for the presence of (b'JFIF', b'Exif') in the header, which is excluding some valid JPEG file. This is an example of not recognised ile -- files: e2006bd7-51d7-4554-9738-ea13207fd104.jpg messages: 348161 nosy: pchopin priority: normal severity: normal status: open title: Imghdr doesnt recognise some jpeg versions: Python 3.7 Added file: https://bugs.python.org/file48491/e2006bd7-51d7-4554-9738-ea13207fd104.jpg ___ Python tracker <https://bugs.python.org/issue37629> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37209] Add what's new entries for pickle enhancements
Change by Pierre Glaser : -- keywords: +patch pull_requests: +14319 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/14503 ___ Python tracker <https://bugs.python.org/issue37209> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37244] test_multiprocessing_forkserver: test_resource_tracker() failed on x86 Gentoo Refleaks 3.8
Change by Pierre Glaser : -- keywords: +patch pull_requests: +14110 stage: -> patch review pull_request: https://github.com/python/cpython/pull/14288 ___ Python tracker <https://bugs.python.org/issue37244> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36888] Create a way to check that the parent process is alive for deamonized processes
Change by Pierre Glaser : -- pull_requests: +14108 stage: resolved -> patch review pull_request: https://github.com/python/cpython/pull/14286 ___ Python tracker <https://bugs.python.org/issue36888> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37185] use os.memfd_create in multiprocessing.shared_memory?
New submission from Pierre Glaser : Hi, Following https://bugs.python.org/issue26836, I started thinking about using memfd_create instead of shm_open for creating shared-memory segments in multiprocessing.shared_memory. The main advantage of memfd_create over shm_open is that the generated resources management is easier: a segment created using using memfd_create is released once all references to the segment are dropped. This is not the case for segments created using shm_open, for which additional resource tracking is needed (using the new multiprocessing.resource_tracker) The main difference between those two calls is that segments created using memfd_create are anonymous and can only be accessed using file descriptors. The name argument in the signature serves only for debugging purposes. On the contrary, shm_open generates segments that map to a file in /dev/shm: therefore, segments each have unique names. Would we decide to switch from shm_open to memfd_create, the name behavior will also change. How big of a deal would that be? -- messages: 344881 nosy: davin, pierreglaser, pitrou priority: normal severity: normal status: open title: use os.memfd_create in multiprocessing.shared_memory? type: resource usage versions: Python 3.9 ___ Python tracker <https://bugs.python.org/issue37185> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26836] Add memfd_create to os module
Pierre Glaser added the comment: >From a quick skim at the man page of memfd_create, this looks promising. -- ___ Python tracker <https://bugs.python.org/issue26836> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36686] Docs: asyncio.loop.subprocess_exec documentation is confusing, it's not clear how to inherit stdin, stdout or stderr in the subprocess
Change by Simon Bernier St-Pierre : -- stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue36686> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36686] Docs: asyncio.loop.subprocess_exec documentation is confusing, it's not clear how to inherit stdin, stdout or stderr in the subprocess
Change by Simon Bernier St-Pierre : -- keywords: +patch pull_requests: +13493 stage: -> patch review pull_request: https://github.com/python/cpython/pull/13586 ___ Python tracker <https://bugs.python.org/issue36686> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36977] SharedMemoryManager should relase its resources when its parent process dies
Change by Pierre Glaser : -- keywords: +patch pull_requests: +13360 stage: -> patch review ___ Python tracker <https://bugs.python.org/issue36977> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36977] SharedMemoryManager should relase its resources when its parent process dies
New submission from Pierre Glaser : The new multiprocessing.managers.SharedMemoryManager spawns a server that delivers memory segments to a parent Python process. If the parent process terminates unexpectedly, we should now make the manager process notice this termination it using the recent multiprocessing.parent_process object (that comes with a sentinel), and shut it down. -- components: Library (Lib) messages: 342948 nosy: pierreglaser, pitrou priority: normal severity: normal status: open title: SharedMemoryManager should relase its resources when its parent process dies ___ Python tracker <https://bugs.python.org/issue36977> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36950] test.support: add an helper to wait for an event with a timeout
Pierre Glaser added the comment: Just did so. -- ___ Python tracker <https://bugs.python.org/issue36950> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36950] test.support: add an helper to wait for an event with a timeout
Change by Pierre Glaser : -- keywords: +patch pull_requests: +13318 stage: -> patch review ___ Python tracker <https://bugs.python.org/issue36950> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36950] test.support: add an helper to wait for an event with a timeout
Pierre Glaser added the comment: Lib/test/test_asyncio/utils.py defines a similar helper: def run_until(loop, pred, timeout=30): deadline = time.monotonic() + timeout while not pred(): if timeout is not None: timeout = deadline - time.monotonic() if timeout <= 0: raise futures.TimeoutError() loop.run_until_complete(tasks.sleep(0.001)) If we trim the ``loop`` usage, we have a rather simple helper can be used to rewrite a decent number of tests, such as: - _test_multiprocessing.py _TestBarrier._test_reset_f - _test_multiprocessing.py _TestPoolWorkerLifetime.test_pool_worker_lifetime - _test_multiprocessing.py TestSyncManagerTypes.test_wait_proc_exit - fork_wait. ForkWait.test_wait - test_concurrent_futures.py FailingInitializerMixin.test_initializer - test_fork1.py ForkTest.waitimpl - test_logging.py HandlerTests.test_post_fork_child_no_deadlock - test_os. Win32KillTests._kill - test_signal.py StressTest.test_stress_delivery_dependent - test_signal.py StressTest.test_stress_delivery_simulatenous - test_wait4.py Wait4Test.wait_impl As well as some top-level commands in: - test_multiprocessing_main_handling.py some top level instructions - subprocessdata/sigchlild_ignore.py - support/__init__.py I also witnessed some slightly more complex patterns that does not easily fit into the asyncio helper: # eintr_tester.py FNTREINTLTest._lock while True: # synchronize the subprocess dt = time.monotonic() - start_time if dt > 60.0: raise Exception("failed to sync child in %.1f sec" % dt) try: lock_func(f, fcntl.LOCK_EX | fcntl.LOCK_NB) lock_func(f, fcntl.LOCK_UN) time.sleep(0.01) except BlockingIOError: break Which is also (IMO) the case for the lines quoted by Victor. However, such more complex structures do not seem to appear that often, so sticking to run_until and moving it to test.support.script_helper may be enough. -- ___ Python tracker <https://bugs.python.org/issue36950> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36950] test.support: add an helper to wait for an event with a timeout
Change by Pierre Glaser : -- nosy: +pierreglaser ___ Python tracker <https://bugs.python.org/issue36950> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24882] ThreadPoolExecutor doesn't reuse threads until #threads == max_workers
Change by Pierre Glaser : -- nosy: +pierreglaser ___ Python tracker <https://bugs.python.org/issue24882> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35933] python doc does not say that the state kwarg in Pickler.save_reduce can be a tuple (and not only a dict)
Change by Pierre Glaser : -- stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue35933> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36368] server process of shared_memory shuts down if KeyboardInterrupt
Change by Pierre Glaser : -- stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue36368> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36894] test_multiprocessing_spawn regression on Windows
Pierre Glaser added the comment: Thanks for the fix Antoine. -- ___ Python tracker <https://bugs.python.org/issue36894> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36867] Make semaphore_tracker track other system resources
Change by Pierre Glaser : -- pull_requests: +13203 ___ Python tracker <https://bugs.python.org/issue36867> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36867] Make semaphore_tracker track other system resources
Pierre Glaser added the comment: We can do that, or maybe we can try to wait on the `resource_tracker's` pid? -- ___ Python tracker <https://bugs.python.org/issue36867> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36867] Make semaphore_tracker track other system resources
Change by Pierre Glaser : -- pull_requests: +13182 ___ Python tracker <https://bugs.python.org/issue36867> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36867] Make semaphore_tracker track other system resources
Pierre Glaser added the comment: Actually, I was properly unlinking the shared_memory segments. The warning messages are due to bad interactions between the ResourceTracker and the SharedMemoryManager object. In this particular case, it's easy to change a little bit the problematic test to avoid the warnings. I will focus on solving those bad interactions right after. -- ___ Python tracker <https://bugs.python.org/issue36867> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36867] Make semaphore_tracker track other system resources
Pierre Glaser added the comment: Yes, one test I wrote in an unrelated commit does not unlink a memory segment. Now the ResourceTracker complains. Fixing it now. -- ___ Python tracker <https://bugs.python.org/issue36867> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36867] Make semaphore_tracker track other system resources
Pierre Glaser added the comment: Shared memory segments are now tracked by the brand new resource_tracker! Thanks Antoine for the review. Does anyone have an opinion on introducing a public API for users to make the resource_tracker track resources of their choice? What We have in mind is: - making public the existing resource_tracker.register/unregister - adding a new function, resource_tracker.make_trackable(resource_type, cleanup_func), where: * resource_type is a string (an identifier that will be used each time a resource of the type resource_type needs tracking, via the call resource_tracker.register(resource_name, resource_type) * cleanup_func must be a callable taking a single string as argument (the name of the resource that needs tracking). This function will be called after the end of a process for reach resource of type resource_type the process did not clean properly Under the hood, make_trackable simply populates resource_tracker._CLEANUP_FUNCS with new items. Here is a simple example: import os import resource_tracker import shutil from multiprocessing import util class ClassCreatingAFolder: """Class where each instance creates a temporary folder. Each temporary folder is supposed to exist for the duration of the instance that created it. """ def __init__(self, folder_name): self.folder_name = folder_name os.mkdir(folder_name) # any instance normally garbage-collected should remove its folder, and # notice the resource_tracker that its folder was correctly removed. util.Finalize(self, ClassCreatingAFolder.cleanup, args=(folder_name,)) # If this session quits abruptly, the finalizer will not be called for # the instances of ClassCreatingAFolder that were still alive # before the shutdown. The resource_tracker comes into play, and removes # the folders associated to each of these resources. resource_tracker.register( folder_name, # argument to shutil.rmtree "ClassCreatingAFolder") @staticmethod def cleanup(folder_name): resource_tracker.unregister(folder_name, "ClassCreatingAFolder") shutil.rmtree(folder_name) # Tell the resource_tracker how to cleanup resources created by # ClassCreatingAFolder instances resource_tracker.make_trackable("ClassCreatingAFolder", shutil.rmtree) Typical resources that can be made trackable include memmaped objects, temporary folders. Our use-case is joblib that has its own mmap type that we would like to track using the semaphore_tracker. Any thoughts? -- ___ Python tracker <https://bugs.python.org/issue36867> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36338] urlparse of urllib returns wrong hostname
Change by Pierre Glaser : -- pull_requests: +13146 ___ Python tracker <https://bugs.python.org/issue36338> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36874] Support CDATA by xml.etree.(c)ElementTree
New submission from Pierre van de Laar : I would like to add information to CDATA in an Xml Tree. Turns out I am not the only one: https://stackoverflow.com/questions/174890/how-to-output-cdata-using-elementtree Can the library be extended to also support CDATA (similar to Comment)? Saves a lot of hacking... -- components: XML messages: 342067 nosy: Pierre van de Laar priority: normal severity: normal status: open title: Support CDATA by xml.etree.(c)ElementTree type: enhancement versions: Python 3.9 ___ Python tracker <https://bugs.python.org/issue36874> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36867] Make semaphore_tracker track other system resources
Change by Pierre Glaser : -- keywords: +patch pull_requests: +13132 stage: -> patch review ___ Python tracker <https://bugs.python.org/issue36867> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36867] Make semaphore_tracker track other system resources
New submission from Pierre Glaser : Hi all, Olivier Grisel, Thomas Moreau and myself are currently working on increasing the range of action of the semaphore_tracker in Python. multiprocessing.semaphore_tracker is a little known module, that launches a server process used to track the life cycle of semaphores created in a python session, and potentially cleanup those semaphores after all python processes of the session terminated. Normally, python processes cleanup semaphores they create. This is however not not guaranteed if the processes get violently interrupted (using for example the bash command "killall python") A note on why the semaphore_tracker was introduced: Cleaning up semaphores after termination is important because the system only supports a limited number of named semaphores, and they will not be automatically removed till the next reboot. Now, Python 3.8 introduces shared memory segments creation. Shared memory is another sensitive global system resource. Currently, unexpected termination of processes that created memory segments will result in leaking those memory segments. This can be problematic for large compute clusters with many users and that are rebooted rarely. For this reason, we expanded the semaphore_tracker to also track shared memory segments, and renamed it resource_tracker. Shared memory segments get automatically tracked by the resource tracker when they are created. This is a first, self-contained fix. (1) Additionally, supporting shared memory tracking led to a more generic design for the resource_tracker. The resource_tracker can be now easily extended to track arbitrary resource types. A public API could potentially be exposed for users willing to track other types. One for example may want to add tracking for temporary folders creating during python sessions. Another use case is the one of joblib, which is a widely-used parallel-computing package, and also the backend of scikit-learn. Joblib relies heavily on memmapping. A public API could extend the resource_tracker to track memmap-ed objects with very little code. Therefore, this issue serves two purposes: - referencing the semaphore_tracker enhancement mentioned in (1) - discussing a potentially public resource_tracker API. -- components: Library (Lib) messages: 341987 nosy: pablogsal, pierreglaser, pitrou priority: normal severity: normal status: open title: Make semaphore_tracker track other system resources type: resource usage versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue36867> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36686] Docs: asyncio.loop.subprocess_exec documentation is confusing, it's not clear how to inherit stdin, stdout or stderr in the subprocess
Simon Bernier St-Pierre added the comment: Could be cool to also mention that `encoding` / `errors` does not work yet. https://bugs.python.org/issue31087 -- ___ Python tracker <https://bugs.python.org/issue36686> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36687] subprocess encoding
Change by Simon Bernier St-Pierre : -- stage: -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue36687> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36687] subprocess encoding
Change by Simon Bernier St-Pierre : -- nosy: sbstp priority: normal severity: normal status: open title: subprocess encoding ___ Python tracker <https://bugs.python.org/issue36687> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com