Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pypy.org
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
This instance will be upgraded to Heptapod 17.9.0rc1 on 2025-03-27 between 17:00 and 18:00 UTC+2
Show more breadcrumbs
PyPy
pypy.org
Commits
097e4f70
Commit
097e4f70
authored
8 years ago
by
Armin Rigo
Browse files
Options
Downloads
Patches
Plain Diff
Copy some documentation about ``-X track-resources`` here as well
parent
db1924be
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compat.html
+10
-0
10 additions, 0 deletions
compat.html
source/compat.txt
+12
-0
12 additions, 0 deletions
source/compat.txt
with
22 additions
and
0 deletions
compat.html
+
10
−
0
View file @
097e4f70
...
...
@@ -116,6 +116,16 @@
<div
class=
"syntax python"
><pre><span></span><span
class=
"n"
>
f
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"nb"
>
open
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
filename
"
</span><span
class=
"p"
>
,
</span>
<span
class=
"s2"
>
"
w
"
</span><span
class=
"p"
>
)
</span><br/><span
class=
"n"
>
f
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
write
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
stuff
"
</span><span
class=
"p"
>
)
</span><br/><span
class=
"n"
>
f
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
close
</span><span
class=
"p"
>
()
</span><br/></pre></div>
<p>
or using the
<tt
class=
"docutils literal"
>
with
</tt>
keyword
</p>
<div
class=
"syntax python"
><pre><span></span><span
class=
"k"
>
with
</span>
<span
class=
"nb"
>
open
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
filename
"
</span><span
class=
"p"
>
,
</span>
<span
class=
"s2"
>
"
w
"
</span><span
class=
"p"
>
)
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"n"
>
f
</span><span
class=
"p"
>
:
</span><br/>
<span
class=
"n"
>
f
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
write
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
stuff
"
</span><span
class=
"p"
>
)
</span><br/></pre></div>
<p>
The same problem
–
not closing your files
–
can also show up if your
program opens a large number of files without closing them explicitly.
In that case, you can easily hit the system limit on the number of file
descriptors that are allowed to be opened at the same time.
</p>
<p>
Since release 5.4, PyPy can be run with the command-line option
<tt
class=
"docutils literal"
><span
class=
"pre"
>
-X
</span>
<span
class=
"pre"
>
track-resources
</span></tt>
(as in,
<tt
class=
"docutils literal"
>
pypy
<span
class=
"pre"
>
-X
</span>
<span
class=
"pre"
>
track-resources
</span>
myprogram.py
</tt>
).
This produces a ResourceWarning when the GC closes a non-closed file or
socket. The traceback for the place where the file or socket was
allocated is given as well, which aids finding places where
<tt
class=
"docutils literal"
>
close()
</tt>
is missing.
</p>
<p>
Similarly, remember that you must
<tt
class=
"docutils literal"
>
close()
</tt>
a non-exhausted
generator in order to have its pending
<tt
class=
"docutils literal"
>
finally
</tt>
or
<tt
class=
"docutils literal"
>
with
</tt>
clauses executed immediately:
</p>
...
...
This diff is collapsed.
Click to expand it.
source/compat.txt
+
12
−
0
View file @
097e4f70
...
...
@@ -86,6 +86,18 @@
with open("filename", "w") as f:
f.write("stuff")
The same problem---not closing your files---can also show up if your
program opens a large number of files without closing them explicitly.
In that case, you can easily hit the system limit on the number of file
descriptors that are allowed to be opened at the same time.
Since release 5.4, PyPy can be run with the command-line option ``-X
track-resources`` (as in, ``pypy -X track-resources myprogram.py``).
This produces a ResourceWarning when the GC closes a non-closed file or
socket. The traceback for the place where the file or socket was
allocated is given as well, which aids finding places where ``close()``
is missing.
Similarly, remember that you must ``close()`` a non-exhausted
generator in order to have its pending ``finally`` or ``with``
clauses executed immediately:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment