Skip to content

Commit e2ce681

Browse files
authored
Merge pull request #29 from mattip/compat
remove stdlib from the website compat overview
2 parents f00eadc + d12d649 commit e2ce681

File tree

1 file changed

+33
-49
lines changed

1 file changed

+33
-49
lines changed

pages/compat.rst

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,31 @@
66
.. link:
77
.. description:
88
9-
PyPy implements the Python language version 2.7.18. It supports all of the core
10-
language, passing Python test suite (with minor modifications that were
11-
already accepted in the main python in newer versions). It supports most
12-
of the commonly used Python `standard library modules`_; details below.
13-
14-
PyPy3 implements the Python language version 3.7.9. It has been released,
15-
but Python is a large language and it is quite possible that a few things are missing.
16-
17-
PyPy has support for the `CPython C API`_, however there are constructs
18-
that are `not compatible`. We strongly advise use of `CFFI`_
19-
instead. CFFI come builtin with PyPy. Many libraries will require
20-
a bit of effort to work, but there are known success stories. Check out
21-
PyPy blog for updates
22-
23-
C extensions need to be recompiled for PyPy in order to work. Depending on
24-
your build system, it might work out of the box or will be slightly harder.
25-
26-
Standard library modules supported by PyPy. Note that large parts of python
27-
library are implemented in pure python, so they don't have to be listed
28-
there. Please just check if it imports. If it imports, it should work:
29-
30-
``__builtin__``, ``__pypy__``, ``_ast``, ``_cffi_backend``, ``_codecs``,
31-
``_collections``, ``_continuation``, ``_csv``, ``_file``, ``_hashlib``,
32-
``_io``, ``_locale``, ``_lsprof``, ``_md5``, ``_minimal_curses``,
33-
``_multibytecodec``, ``_multiprocessing``, ``_numpypy``, ``_pickle_support``,
34-
``_pypyjson``, ``_random``, ``_rawffi``, ``_sha``, ``_socket``, ``_sre``,
35-
``_ssl``, ``_struct``, ``_testing``, ``_warnings``, ``_weakref``, ``array``,
36-
``binascii``, ``bz2``, ``cStringIO``, ``cmath``, ``cppyy``, ``cpyext``,
37-
``crypt``, ``errno``, ``exceptions``, ``fcntl``, ``gc``, ``imp``,
38-
``itertools``, ``marshal``, ``math``, ``mmap``, ``operator``, ``parser``,
39-
``posix``, ``pwd``, ``pyexpat``, ``pypyjit``, ``select``, ``signal``,
40-
``symbol``, ``sys``, ``termios``, ``thread``, ``time``, ``token``,
41-
``unicodedata``, ``zipimport``, ``zlib``
42-
43-
Supported, and written in pure Python:
44-
45-
``cPickle``, ``ctypes``, ``datetime``, ``dbm``, ``_functools``, ``grp``,
46-
``readline``, ``resource``, ``sqlite3``, ``syslog``
47-
48-
All modules that are pure python in CPython of course work.
49-
50-
The main difference that is not going to be fixed is that PyPy does
51-
not support refcounting semantics. The following code won't fill the
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+
15+
Pure python code works, but there are a few differences with object lifetime
16+
management. Modules that use the `CPython C API`_ will probably work, but will
17+
not achieve a speedup via the JIT. We encourage library authors to use `CFFI`_
18+
instead.
19+
20+
If you are looking for how to use PyPy with the scientific python ecosystem,
21+
we encourage you to use `conda`_, since they repackage common libraries like
22+
scikit-learn and SciPy for PyPy.
23+
24+
Refcounting, ``__del__``, and resource use
25+
------------------------------------------
26+
27+
The main difference in pure-python code that is not going to be fixed is that
28+
PyPy does
29+
not support refcounting semantics for "automatically" releasing state when
30+
an object's ``__del__`` is called. The following code won't fill the
5231
file immediately, but only after a certain period of time, when the GC
53-
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:
5434

5535
.. code-block:: python
5636
@@ -102,8 +82,11 @@ as on CPython: they run "some time later" in PyPy (or not at all if
10282
the program finishes running in the meantime). See `more details
10383
here`_.
10484

105-
Note that PyPy returns unused memory to the operating system if there
106-
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
10790
important to realize that you may not see this in ``top``. The unused
10891
pages are marked with ``MADV_FREE``, which tells the system "if you
10992
need more memory at some point, grab this page". As long as memory is
@@ -112,12 +95,13 @@ this rule are systems with no ``MADV_FREE``, where we use
11295
``MADV_DONTNEED``, which forcefully lowers the ``RES``. This includes
11396
Linux <= 4.4.)
11497

98+
More info
99+
---------
100+
115101
A more complete list of known differences is available at `our dev site`_.
116102

117103
.. _`CPython C API`: http://docs.python.org/c-api/
118104
.. _`CFFI`: http://cffi.readthedocs.org/
119-
.. _`not compatible`: http://doc.pypy.org/en/latest/cpython_differences.html#c-api-differences
120-
.. _`standard library modules`: http://docs.python.org/library/
105+
.. _`conda`: https://conda-forge.org/blog/posts/2020-03-10-pypy/
121106
.. _`our dev site`: http://pypy.readthedocs.org/en/latest/cpython_differences.html
122107
.. _`more details here`: http://pypy.readthedocs.org/en/latest/cpython_differences.html#differences-related-to-garbage-collection-strategies
123-
.. _`List of installable top 1000 PyPI packages`: http://packages.pypy.org

0 commit comments

Comments
 (0)