[PATCH 2 of 2] patches: release the GIL while applying the patch

Gregory Szorc gregory.szorc at gmail.com
Tue Feb 6 16:14:03 EST 2018


On Tue, Feb 6, 2018 at 6:28 AM, Boris Feld <boris.feld at octobus.net> wrote:

> # HG changeset patch
> # User Boris Feld <boris.feld at octobus.net>
> # Date 1517839431 -3600
> #      Mon Feb 05 15:03:51 2018 +0100
> # Node ID 345f1c897538cd2b0a5a2fd3952b880206fd9339
> # Parent  eee9cca843bc557274945688ea52e16539d45e67
> # EXP-Topic parallel-patching
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r
> 345f1c897538
> patches: release the GIL while applying the patch
>
> This will allow multiple threads to apply patches at the same time.
>

Please use Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS macros, as that
is what the Python docs recommend. I'm not sure why we don't do this
consistently in our code today. IMO we should port existing code to these
macros.


>
> diff --git a/mercurial/cext/mpatch.c b/mercurial/cext/mpatch.c
> --- a/mercurial/cext/mpatch.c
> +++ b/mercurial/cext/mpatch.c
> @@ -77,6 +77,7 @@ patches(PyObject *self, PyObject *args)
>         int r = 0;
>         char *out;
>         Py_ssize_t len, outlen, inlen;
> +       PyThreadState *_save;
>
>         if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins))
>                 return NULL;
> @@ -110,7 +111,9 @@ patches(PyObject *self, PyObject *args)
>                 goto cleanup;
>         }
>         out = PyBytes_AsString(result);
> +       _save = PyEval_SaveThread();
>         r = mpatch_apply(out, in, inlen, patch);
> +       PyEval_RestoreThread(_save);
>         if (r < 0) {
>                 Py_DECREF(result);
>                 result = NULL;
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20180206/7ad8143e/attachment.html>


More information about the Mercurial-devel mailing list