path: root/community/rstcheck/02-Close-the-multiprocessing.pool-after-use.patch
blob: d0680ef23dfbfda27313632d0b05b3d7d9d12d3c (plain) (tree)


From 5e6e995305f66246e8f98acd15de2c39a75efa5b Mon Sep 17 00:00:00 2001
From: Keith Maxwell <keith.maxwell@gmail.com>
Date: Mon, 11 May 2020 20:53:14 +0100
Subject: [PATCH] Close the multiprocessing.pool after use

So that the tests do not hang intermittently

When preparing to release Alpine Linux 3.12, the tests for this package
would hang intermittently. This problem was isolated to the tests in
test.bash that run rstcheck.py over multiple files.

The documentation for multiprocessing.pool explains that:

> Warning multiprocessing.pool objects have internal resources that need
> to be properly managed (like any other resource) by using the pool as
> a context manager or by calling close() and terminate() manually.
> Failure to do this can lead to the process hanging on finalization.

> Note that is not correct to rely on the garbage colletor to destroy
> the pool as CPython does not assure that the finalizer of the pool
> will be called (see object.__del__() for more information).


Before this commit close() was not called on the multiprocessing pool;
after this commit close() is called.

The change in this commit was tested in an Alpine Linux container:

    podman run -ti --rm -v $PWD:/srv:Z -w /srv alpine:edge sh

By running:

    apk add alpine-sdk python3 py3-docutils py3-setuptools bash
    python3 setup.py build
    sed -i '1s|^#!/usr/bin/env python$|#!/usr/bin/python3|' rstcheck.py
    python3 ./test_rstcheck.py
    bash ./test.bash
 rstcheck.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rstcheck.py b/rstcheck.py
index a13ec2b..959808a 100755
--- a/rstcheck.py
+++ b/rstcheck.py
@@ -981,6 +981,7 @@ def main():
         except (IOError, UnicodeError) as exception:
             status = 1
+        pool.close()
         return status