6
6
.. link:
7
7
.. description:
8
8
9
+ The goal of this page is to point out some of the differences between running
10
+ python with PyPy and with CPython
11
+
12
+ TL;DR
13
+ -----
14
+
9
15
Pure python code works, but there are a few differences with object lifetime
10
16
management. Modules that use the `CPython C API `_ will probably work, but will
11
17
not achieve a speedup via the JIT. We encourage library authors to use `CFFI `_
@@ -15,11 +21,16 @@ If you are looking for how to use PyPy with the scientific python ecosystem,
15
21
we encourage you to use `conda `_, since they repackage common libraries like
16
22
scikit-learn and SciPy for PyPy.
17
23
24
+ Refcounting, ``__del__ ``, and resource use
25
+ ------------------------------------------
26
+
18
27
The main difference in pure-python code that is not going to be fixed is that
19
28
PyPy does
20
- not support refcounting semantics. The following code won't fill the
29
+ not support refcounting semantics for "automatically" releasing state when
30
+ an object's ``__del__ `` is called. The following code won't fill the
21
31
file immediately, but only after a certain period of time, when the GC
22
- does a collection and flushes the output:
32
+ does a collection and flushes the output, since the file is only closed when
33
+ the ``__del__ `` method is called:
23
34
24
35
.. code-block :: python
25
36
@@ -71,8 +82,11 @@ as on CPython: they run "some time later" in PyPy (or not at all if
71
82
the program finishes running in the meantime). See `more details
72
83
here `_.
73
84
74
- Note that PyPy returns unused memory to the operating system if there
75
- is a madvise() system call (at least Linux, OS X, BSD) or on Windows. It is
85
+ Why is memory usage so high?
86
+ ----------------------------
87
+
88
+ Note that PyPy returns unused memory to the operating system only after
89
+ a madvise() system call (at least Linux, OS X, BSD) or on Windows. It is
76
90
important to realize that you may not see this in ``top ``. The unused
77
91
pages are marked with ``MADV_FREE ``, which tells the system "if you
78
92
need more memory at some point, grab this page". As long as memory is
@@ -81,6 +95,9 @@ this rule are systems with no ``MADV_FREE``, where we use
81
95
``MADV_DONTNEED ``, which forcefully lowers the ``RES ``. This includes
82
96
Linux <= 4.4.)
83
97
98
+ More info
99
+ ---------
100
+
84
101
A more complete list of known differences is available at `our dev site `_.
85
102
86
103
.. _`CPython C API` : http://docs.python.org/c-api/
0 commit comments