# SOME DESCRIPTIVE TITLE. # Copyright (C) 2001 Python Software Foundation # This file is distributed under the same license as the Python package. # FIRST AUTHOR , YEAR. # # Translators: # tomo, 2021 # Yusuke Miyazaki , 2021 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2025-05-23 14:20+0000\n" "PO-Revision-Date: 2021-06-28 01:04+0000\n" "Last-Translator: Yusuke Miyazaki , 2021\n" "Language-Team: Japanese (https://app.transifex.com/python-doc/teams/5390/" "ja/)\n" "Language: ja\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" #: ../../library/devmode.rst:4 msgid "Python Development Mode" msgstr "Python 開発モード" #: ../../library/devmode.rst:8 msgid "" "The Python Development Mode introduces additional runtime checks that are " "too expensive to be enabled by default. It should not be more verbose than " "the default if the code is correct; new warnings are only emitted when an " "issue is detected." msgstr "" #: ../../library/devmode.rst:13 msgid "" "It can be enabled using the :option:`-X dev <-X>` command line option or by " "setting the :envvar:`PYTHONDEVMODE` environment variable to ``1``." msgstr "" #: ../../library/devmode.rst:16 msgid "See also :ref:`Python debug build `." msgstr "" #: ../../library/devmode.rst:19 msgid "Effects of the Python Development Mode" msgstr "Python 開発モードの影響" #: ../../library/devmode.rst:21 msgid "" "Enabling the Python Development Mode is similar to the following command, " "but with additional effects described below::" msgstr "" "Python 開発モードを有効化することは次のコマンドに似ていますが、以下で説明され" "る追加の影響があります::" #: ../../library/devmode.rst:24 msgid "" "PYTHONMALLOC=debug PYTHONASYNCIODEBUG=1 python -W default -X faulthandler" msgstr "" "PYTHONMALLOC=debug PYTHONASYNCIODEBUG=1 python -W default -X faulthandler" #: ../../library/devmode.rst:26 msgid "Effects of the Python Development Mode:" msgstr "Python 開発モードの影響:" #: ../../library/devmode.rst:28 msgid "" "Add ``default`` :ref:`warning filter `. The " "following warnings are shown:" msgstr "" "``default`` の :ref:`警告フィルタ ` を追加しま" "す。次の警告が表示されます:" #: ../../library/devmode.rst:31 msgid ":exc:`DeprecationWarning`" msgstr ":exc:`DeprecationWarning`" #: ../../library/devmode.rst:32 msgid ":exc:`ImportWarning`" msgstr ":exc:`ImportWarning`" #: ../../library/devmode.rst:33 msgid ":exc:`PendingDeprecationWarning`" msgstr ":exc:`PendingDeprecationWarning`" #: ../../library/devmode.rst:34 msgid ":exc:`ResourceWarning`" msgstr ":exc:`ResourceWarning`" #: ../../library/devmode.rst:36 msgid "" "Normally, the above warnings are filtered by the default :ref:`warning " "filters `." msgstr "" "通常、上記の警告は デフォルトの :ref:`警告フィルタ ` によりフィルタリングされます。" #: ../../library/devmode.rst:39 msgid "" "It behaves as if the :option:`-W default <-W>` command line option is used." msgstr "" #: ../../library/devmode.rst:41 msgid "" "Use the :option:`-W error <-W>` command line option or set the :envvar:" "`PYTHONWARNINGS` environment variable to ``error`` to treat warnings as " "errors." msgstr "" #: ../../library/devmode.rst:45 msgid "Install debug hooks on memory allocators to check for:" msgstr "" #: ../../library/devmode.rst:47 msgid "Buffer underflow" msgstr "" #: ../../library/devmode.rst:48 msgid "Buffer overflow" msgstr "" #: ../../library/devmode.rst:49 msgid "Memory allocator API violation" msgstr "" #: ../../library/devmode.rst:50 msgid "Unsafe usage of the GIL" msgstr "" #: ../../library/devmode.rst:52 msgid "See the :c:func:`PyMem_SetupDebugHooks` C function." msgstr "" #: ../../library/devmode.rst:54 msgid "" "It behaves as if the :envvar:`PYTHONMALLOC` environment variable is set to " "``debug``." msgstr "" #: ../../library/devmode.rst:57 msgid "" "To enable the Python Development Mode without installing debug hooks on " "memory allocators, set the :envvar:`PYTHONMALLOC` environment variable to " "``default``." msgstr "" #: ../../library/devmode.rst:61 msgid "" "Call :func:`faulthandler.enable` at Python startup to install handlers for " "the :const:`~signal.SIGSEGV`, :const:`~signal.SIGFPE`, :const:`~signal." "SIGABRT`, :const:`~signal.SIGBUS` and :const:`~signal.SIGILL` signals to " "dump the Python traceback on a crash." msgstr "" #: ../../library/devmode.rst:66 msgid "" "It behaves as if the :option:`-X faulthandler <-X>` command line option is " "used or if the :envvar:`PYTHONFAULTHANDLER` environment variable is set to " "``1``." msgstr "" #: ../../library/devmode.rst:70 msgid "" "Enable :ref:`asyncio debug mode `. For example, :mod:" "`asyncio` checks for coroutines that were not awaited and logs them." msgstr "" #: ../../library/devmode.rst:73 msgid "" "It behaves as if the :envvar:`PYTHONASYNCIODEBUG` environment variable is " "set to ``1``." msgstr "" #: ../../library/devmode.rst:76 msgid "" "Check the *encoding* and *errors* arguments for string encoding and decoding " "operations. Examples: :func:`open`, :meth:`str.encode` and :meth:`bytes." "decode`." msgstr "" #: ../../library/devmode.rst:80 msgid "" "By default, for best performance, the *errors* argument is only checked at " "the first encoding/decoding error and the *encoding* argument is sometimes " "ignored for empty strings." msgstr "" #: ../../library/devmode.rst:84 msgid "The :class:`io.IOBase` destructor logs ``close()`` exceptions." msgstr "" #: ../../library/devmode.rst:85 msgid "" "Set the :attr:`~sys.flags.dev_mode` attribute of :data:`sys.flags` to " "``True``." msgstr "" #: ../../library/devmode.rst:88 msgid "" "The Python Development Mode does not enable the :mod:`tracemalloc` module by " "default, because the overhead cost (to performance and memory) would be too " "large. Enabling the :mod:`tracemalloc` module provides additional " "information on the origin of some errors. For example, :exc:" "`ResourceWarning` logs the traceback where the resource was allocated, and a " "buffer overflow error logs the traceback where the memory block was " "allocated." msgstr "" #: ../../library/devmode.rst:95 msgid "" "The Python Development Mode does not prevent the :option:`-O` command line " "option from removing :keyword:`assert` statements nor from setting :const:" "`__debug__` to ``False``." msgstr "" #: ../../library/devmode.rst:99 msgid "" "The Python Development Mode can only be enabled at the Python startup. Its " "value can be read from :data:`sys.flags.dev_mode `." msgstr "" #: ../../library/devmode.rst:102 msgid "The :class:`io.IOBase` destructor now logs ``close()`` exceptions." msgstr "" #: ../../library/devmode.rst:105 msgid "" "The *encoding* and *errors* arguments are now checked for string encoding " "and decoding operations." msgstr "" #: ../../library/devmode.rst:111 msgid "ResourceWarning Example" msgstr "ResourceWarning の例" #: ../../library/devmode.rst:113 msgid "" "Example of a script counting the number of lines of the text file specified " "in the command line::" msgstr "" #: ../../library/devmode.rst:116 msgid "" "import sys\n" "\n" "def main():\n" " fp = open(sys.argv[1])\n" " nlines = len(fp.readlines())\n" " print(nlines)\n" " # The file is closed implicitly\n" "\n" "if __name__ == \"__main__\":\n" " main()" msgstr "" "import sys\n" "\n" "def main():\n" " fp = open(sys.argv[1])\n" " nlines = len(fp.readlines())\n" " print(nlines)\n" " # ファイルは暗黙的に閉じられる\n" "\n" "if __name__ == \"__main__\":\n" " main()" #: ../../library/devmode.rst:127 msgid "" "The script does not close the file explicitly. By default, Python does not " "emit any warning. Example using README.txt, which has 269 lines:" msgstr "" #: ../../library/devmode.rst:130 msgid "" "$ python script.py README.txt\n" "269" msgstr "" "$ python script.py README.txt\n" "269" #: ../../library/devmode.rst:135 msgid "" "Enabling the Python Development Mode displays a :exc:`ResourceWarning` " "warning:" msgstr "" #: ../../library/devmode.rst:137 msgid "" "$ python -X dev script.py README.txt\n" "269\n" "script.py:10: ResourceWarning: unclosed file <_io.TextIOWrapper name='README." "rst' mode='r' encoding='UTF-8'>\n" " main()\n" "ResourceWarning: Enable tracemalloc to get the object allocation traceback" msgstr "" "$ python -X dev script.py README.txt\n" "269\n" "script.py:10: ResourceWarning: unclosed file <_io.TextIOWrapper name='README." "rst' mode='r' encoding='UTF-8'>\n" " main()\n" "ResourceWarning: Enable tracemalloc to get the object allocation traceback" #: ../../library/devmode.rst:145 msgid "" "In addition, enabling :mod:`tracemalloc` shows the line where the file was " "opened:" msgstr "" #: ../../library/devmode.rst:148 msgid "" "$ python -X dev -X tracemalloc=5 script.py README.rst\n" "269\n" "script.py:10: ResourceWarning: unclosed file <_io.TextIOWrapper name='README." "rst' mode='r' encoding='UTF-8'>\n" " main()\n" "Object allocated at (most recent call last):\n" " File \"script.py\", lineno 10\n" " main()\n" " File \"script.py\", lineno 4\n" " fp = open(sys.argv[1])" msgstr "" "$ python -X dev -X tracemalloc=5 script.py README.rst\n" "269\n" "script.py:10: ResourceWarning: unclosed file <_io.TextIOWrapper name='README." "rst' mode='r' encoding='UTF-8'>\n" " main()\n" "Object allocated at (most recent call last):\n" " File \"script.py\", lineno 10\n" " main()\n" " File \"script.py\", lineno 4\n" " fp = open(sys.argv[1])" #: ../../library/devmode.rst:160 msgid "" "The fix is to close explicitly the file. Example using a context manager::" msgstr "" #: ../../library/devmode.rst:162 msgid "" "def main():\n" " # Close the file explicitly when exiting the with block\n" " with open(sys.argv[1]) as fp:\n" " nlines = len(fp.readlines())\n" " print(nlines)" msgstr "" "def main():\n" " # ブロックを終了する際に明示的にファイルを閉じる\n" " with open(sys.argv[1]) as fp:\n" " nlines = len(fp.readlines())\n" " print(nlines)" #: ../../library/devmode.rst:168 msgid "" "Not closing a resource explicitly can leave a resource open for way longer " "than expected; it can cause severe issues upon exiting Python. It is bad in " "CPython, but it is even worse in PyPy. Closing resources explicitly makes an " "application more deterministic and more reliable." msgstr "" #: ../../library/devmode.rst:175 msgid "Bad file descriptor error example" msgstr "" #: ../../library/devmode.rst:177 msgid "Script displaying the first line of itself::" msgstr "" #: ../../library/devmode.rst:179 msgid "" "import os\n" "\n" "def main():\n" " fp = open(__file__)\n" " firstline = fp.readline()\n" " print(firstline.rstrip())\n" " os.close(fp.fileno())\n" " # The file is closed implicitly\n" "\n" "main()" msgstr "" "import os\n" "\n" "def main():\n" " fp = open(__file__)\n" " firstline = fp.readline()\n" " print(firstline.rstrip())\n" " os.close(fp.fileno())\n" " # ファイルは暗黙的に閉じられる\n" "\n" "main()" #: ../../library/devmode.rst:190 msgid "By default, Python does not emit any warning:" msgstr "" #: ../../library/devmode.rst:192 msgid "" "$ python script.py\n" "import os" msgstr "" "$ python script.py\n" "import os" #: ../../library/devmode.rst:197 msgid "" "The Python Development Mode shows a :exc:`ResourceWarning` and logs a \"Bad " "file descriptor\" error when finalizing the file object:" msgstr "" #: ../../library/devmode.rst:200 msgid "" "$ python -X dev script.py\n" "import os\n" "script.py:10: ResourceWarning: unclosed file <_io.TextIOWrapper name='script." "py' mode='r' encoding='UTF-8'>\n" " main()\n" "ResourceWarning: Enable tracemalloc to get the object allocation traceback\n" "Exception ignored in: <_io.TextIOWrapper name='script.py' mode='r' " "encoding='UTF-8'>\n" "Traceback (most recent call last):\n" " File \"script.py\", line 10, in \n" " main()\n" "OSError: [Errno 9] Bad file descriptor" msgstr "" "$ python -X dev script.py\n" "import os\n" "script.py:10: ResourceWarning: unclosed file <_io.TextIOWrapper name='script." "py' mode='r' encoding='UTF-8'>\n" " main()\n" "ResourceWarning: Enable tracemalloc to get the object allocation traceback\n" "Exception ignored in: <_io.TextIOWrapper name='script.py' mode='r' " "encoding='UTF-8'>\n" "Traceback (most recent call last):\n" " File \"script.py\", line 10, in \n" " main()\n" "OSError: [Errno 9] Bad file descriptor" #: ../../library/devmode.rst:213 msgid "" "``os.close(fp.fileno())`` closes the file descriptor. When the file object " "finalizer tries to close the file descriptor again, it fails with the ``Bad " "file descriptor`` error. A file descriptor must be closed only once. In the " "worst case scenario, closing it twice can lead to a crash (see :issue:" "`18748` for an example)." msgstr "" #: ../../library/devmode.rst:219 msgid "" "The fix is to remove the ``os.close(fp.fileno())`` line, or open the file " "with ``closefd=False``." msgstr ""