Message from discussion
Preserving python between invocation of Python code.
Received: by 10.180.97.162 with SMTP id eb2mr3085857wib.0.1350672522738;
Fri, 19 Oct 2012 11:48:42 -0700 (PDT)
X-BeenThere: vim_dev@googlegroups.com
Received: by 10.180.20.136 with SMTP id n8ls4129325wie.3.gmail; Fri, 19 Oct
2012 11:48:19 -0700 (PDT)
Received: by 10.180.75.197 with SMTP id e5mr922177wiw.1.1350672499013;
Fri, 19 Oct 2012 11:48:19 -0700 (PDT)
Received: by 10.180.75.197 with SMTP id e5mr922176wiw.1.1350672499002;
Fri, 19 Oct 2012 11:48:19 -0700 (PDT)
Return-Path: <p...@cleversheep.org>
Received: from smtpout.karoo.kcom.com (smtpout.karoo.kcom.com. [212.50.160.34])
by gmr-mx.google.com with ESMTP id bu8si259888wib.2.2012.10.19.11.48.17;
Fri, 19 Oct 2012 11:48:17 -0700 (PDT)
Received-SPF: softfail (google.com: domain of transitioning p...@cleversheep.org does not designate 212.50.160.34 as permitted sender) client-ip=212.50.160.34;
Authentication-Results: gmr-mx.google.com; spf=softfail (google.com: domain of transitioning p...@cleversheep.org does not designate 212.50.160.34 as permitted sender) smtp.mail=p...@cleversheep.org
X-IronPort-AV: E=Sophos;i="4.80,615,1344207600";
d="scan'208";a="671851331"
Received: from unknown (HELO mallard.home) ([91.85.45.221])
by smtpout.karoo.kcom.com with ESMTP; 19 Oct 2012 19:48:17 +0100
Received: from [10.1.1.101] (mallard [10.1.1.101])
by mallard.home (Postfix) with ESMTP id 1AAAC320A3
for <vim_dev@googlegroups.com>; Fri, 19 Oct 2012 19:51:07 +0100 (BST)
Message-ID: <5081A11A.7000305@cleversheep.org>
Date: Fri, 19 Oct 2012 19:51:06 +0100
From: Paul Ollis <p...@cleversheep.org>
Reply-To: p...@cleversheep.org
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120825 Thunderbird/15.0
MIME-Version: 1.0
To: vim_dev@googlegroups.com
Subject: Re: Preserving python between invocation of Python code.
References: <201210110057.q9B0uPe3031478@masaka.moolenaar.net> <507C521B.2030602@cleversheep.org>
In-Reply-To: <507C521B.2030602@cleversheep.org>
Content-Type: multipart/mixed;
boundary="------------040600000802010304000502"
This is a multi-part message in MIME format.
--------------040600000802010304000502
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
On 15/10/12 19:12, Paul Ollis wrote:
> On 11/10/12 01:56, Bram Moolenaar wrote:
>>
>> Paul wrote:
>>
>>> Vim python interface bug.
>>>
> <snip>
>>
>> Does this also need to be changed in the Python 3 interface? Or was it
>> already working correctly there?
>>
> Having had a very quick look, I think the answer is yes.
> I'll do some testing to confirm and submit a suitably updated patch.
>
...and the answer is yes. Updated patch attached
FYI. I have been using a patched version of Vim without any problems for
over a week without issues. My vim set up makes heavy use of Python.
--------------040600000802010304000502
Content-Type: text/x-patch;
name="vim-py-thread-state.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="vim-py-thread-state.patch"
diff -r b042d04009d4 src/if_python.c
--- a/src/if_python.c Sat Oct 06 19:10:36 2012 +0200
+++ b/src/if_python.c Fri Oct 19 19:45:57 2012 +0100
@@ -740,9 +740,13 @@
#else
PyMac_Initialize();
#endif
- /* initialise threads */
+ /* Initialise threads, and save the state using PyGILState_Ensure.
+ * Without the call to PyGILState_Ensure, thread specific state (such
+ * as the system trace hook), will be lost between invocations of
+ * Python code.
+ */
PyEval_InitThreads();
-
+ pygilstate = PyGILState_Ensure();
#ifdef DYNAMIC_PYTHON
get_exceptions();
#endif
diff -r b042d04009d4 src/if_python3.c
--- a/src/if_python3.c Sat Oct 06 19:10:36 2012 +0200
+++ b/src/if_python3.c Fri Oct 19 19:45:57 2012 +0100
@@ -709,8 +709,13 @@
#else
PyMac_Initialize();
#endif
- /* initialise threads, must be after Py_Initialize() */
+ /* Initialise threads, and save the state using PyGILState_Ensure.
+ * Without the call to PyGILState_Ensure, thread specific state (such
+ * as the system trace hook), will be lost between invocations of
+ * Python code.
+ */
PyEval_InitThreads();
+ pygilstate = PyGILState_Ensure();
#ifdef DYNAMIC_PYTHON3
get_py3_exceptions();
--------------040600000802010304000502--