# Python 3.7 Xenial build started to fail with “failed to map segment from shared object”

**URL:** <https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341>\
**Category:** Python\
**Tags:** xenial\
**Created:** [July 23, 2019, 2:33pm UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341 "2019-07-23T14:33:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ncoghlan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/ncoghlan/32/2314_2.png) [@ncoghlan](https://travis-ci.community/u/ncoghlan)\
**Post date:** [July 23, 2019, 2:33pm UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341/1 "2019-07-23T14:33:47Z")

</div>

The Python peps repo recently started failing to build with cryptic shared library errors.

I have a PR that built successfully 3 days ago, but then failed post-merge a day or so ago:

- [https://travis-ci.org/python/peps/builds/561375964](https://travis-ci.org/python/peps/builds/561375964) (succeeded)
- [https://travis-ci.org/python/peps/builds/562245102](https://travis-ci.org/python/peps/builds/562245102) (failed)

(This isn’t a Python build - it’s using Python to run docutils and other scripts to render the PEPs as HTML)

Both PR builds since then have failed in the same way: [https://github.com/python/peps/pulls?q=is%3Aopen+is%3Apr](https://github.com/python/peps/pulls?q=is%3Aopen+is%3Apr)

---

<div class="post-metadata">

**Author:** ![webknjaz](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/webknjaz/32/34_2.png) [@webknjaz](https://travis-ci.community/u/webknjaz)\
**Post date:** [July 23, 2019, 2:47pm UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341/2 "2019-07-23T14:47:58Z")

</div>

`binascii` c-ext didn’t get compiled?  
cc @BanzaiMan

```auto
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/docutils/writers/ __init__.py", line 140, in get_writer_class
    module = __import__ (writer_name, globals(), locals(), level=1)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/docutils/writers/pep_html/ __init__.py", line 18, in <module>
    from docutils.writers import html4css1
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/docutils/writers/html4css1/ __init__.py", line 21, in <module>
    from docutils.writers import _html_base
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/docutils/writers/_html_base.py", line 23, in <module>
    import urllib.request, urllib.parse, urllib.error
  File "/opt/python/3.7.1/lib/python3.7/urllib/request.py", line 84, in <module>
    import base64
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/base64.py", line 11, in <module>
    import binascii
ImportError: /home/travis/virtualenv/python3.7.1/lib/python3.7/lib-dynload/binascii.cpython-37m-x86_64-linux-gnu.so: failed to map segment from shared object

```

---

<div class="post-metadata">

**Author:** ![dominic](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/dominic/32/14_2.png) [@dominic](https://travis-ci.community/u/dominic)\
**Post date:** [July 23, 2019, 3:16pm UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341/3 "2019-07-23T15:16:21Z")

</div>

I see that `docutils` was changed in between i.e.

- [docutils-0.14](https://travis-ci.org/python/peps/jobs/561375965#L200): ✅
- [docutils-0.15](https://travis-ci.org/python/peps/jobs/562245103#L188): ❌

Can you pin down `docutils`'s version to 0.14 and let us know if it helps?

Thanks!

---

<div class="post-metadata">

**Author:** ![webknjaz](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/webknjaz/32/34_2.png) [@webknjaz](https://travis-ci.community/u/webknjaz)\
**Post date:** [July 23, 2019, 4:34pm UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341/4 "2019-07-23T16:34:21Z")

</div>

but the exception is clearly happening during binascii import time

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [July 23, 2019, 9:33pm UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341/5 "2019-07-23T21:33:57Z")

</div>

Looking around the Net, “failed to map segment from shared object” is usually accompanied by an additional message specifying the reason. Since in this case, it isn’t and due to below, **this looks like an out of memory condition. Use `make -j$(nproc)` instead of `make -j`.**

> <https://unix.stackexchange.com/questions/496292/what-does-a-failed-to-map-segment-from-shared-object-error-mean>

> <https://unix.stackexchange.com/questions/316644/is-make-j-with-no-argument-dangerous>

> <https://stackoverflow.com/questions/2499070/gnu-make-should-the-number-of-jobs-equal-the-number-of-cpu-cores-in-a-system>

---

<div class="post-metadata">

**Author:** ![ncoghlan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/ncoghlan/32/2314_2.png) [@ncoghlan](https://travis-ci.community/u/ncoghlan)\
**Post date:** [July 26, 2019, 9:14am UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341/6 "2019-07-26T09:14:05Z")

</div>

Thanks for the PR @native-api!

For anyone curious as to exactly what was changed, [https://github.com/python/peps/pull/1131/files](https://github.com/python/peps/pull/1131/files) is the PR that fixed the problem.

The full PEP repo build is an embarassingly parallel problem (there are hundreds of PEPs, with no build time dependencies between them), so we were inadvertently spinning up hundreds of instances of docutils at once.

(I also suspect it was the fact that I added 2 PEPs right after each other that allowed both PRs to build: individually, there was just enough RAM to do everything in parallel, but together they tipped things over the limit)

---

<div class="post-metadata">

**Author:** ![webknjaz](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/webknjaz/32/34_2.png) [@webknjaz](https://travis-ci.community/u/webknjaz)\
**Post date:** [July 26, 2019, 12:01pm UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341/8 "2019-07-26T12:01:58Z")

</div>

@ncoghlan FYI: [https://github.com/python/peps/pull/1131/files#r307711301](https://github.com/python/peps/pull/1131/files#r307711301)

---

<div class="post-metadata">

**Author:** ![ncoghlan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/ncoghlan/32/2314_2.png) [@ncoghlan](https://travis-ci.community/u/ncoghlan)\
**Post date:** [July 26, 2019, 12:21pm UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341/9 "2019-07-26T12:21:16Z")

</div>

@webknjaz Good info, thanks.

For folks following the thread: `make -j2` is enough to use all the cores allocated to current Travis virtual environments, while `make -j$(nproc)` will start as many processes as exist on the underlying physical machine (currently 32).

That’s not a problem in our particular case (32 docutils instances will barely make a dent in the available RAM - it took hundreds to exhaust it), but could be an issue for more memory hungry build scenarios.

---

<div class="post-metadata">

**Author:** ![webknjaz](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/webknjaz/32/34_2.png) [@webknjaz](https://travis-ci.community/u/webknjaz)\
**Post date:** [July 26, 2019, 1:31pm UTC](https://travis-ci.community/t/python-3-7-xenial-build-started-to-fail-with-failed-to-map-segment-from-shared-object/4341/10 "2019-07-26T13:31:06Z")

</div>

UPD: @native-api and I did some testing and now Travis CI correctly reports 2 cores via `nproc`.
