public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix Python3.9 related runtime problems
Date: Thu, 28 May 2020 08:54:12 -0600	[thread overview]
Message-ID: <87d06ohzzf.fsf@tromey.com> (raw)
In-Reply-To: <20200528044533.1294412-1-kevinb@redhat.com> (Kevin Buettner via Gdb-patches's message of "Wed, 27 May 2020 21:45:33 -0700")

>>>>> "Kevin" == Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> writes:

Kevin> We checked with some Python Developers and were told that we should
Kevin> acquire the GIL prior to calling any Python C API function.  We
Kevin> definitely don't have the GIL for calls of PyOS_InterruptOccurred().

Kevin> I moved class_gdbpy_gil earlier in the file and use it in
Kevin> gdbpy_check_quit_flag() to acquire (and automatically release) the
Kevin> GIL.

This seems like a good plan.

Kevin> In this case, we're trying to call a Python C API function after
Kevin> Py_Finalize() has been called from finalize_python().  I made
Kevin> finalize_python set gdb_python_initialized to false and then cause
Kevin> check_quit_flag() to return early when it's false.

This too.

Kevin> With these changes in place, GDB seems to be working again with
Kevin> Python3.9b1.  I think it likely that there are other problems lurking.
Kevin> I wouldn't be surprised to find that there are other calls into Python
Kevin> where we don't first make sure that we have the GIL.  Further changes
Kevin> may well be needed.

I think we're generally pretty good about this, but yeah, at the same
time I wouldn't be super surprised if there was another lurker
somewhere.

Kevin> I've also tested on Fedora 28, 29, 30, 31, and 32 (all x86_64) using
Kevin> the default (though updated) system installed versions of Python on
Kevin> those OSes.  This means that I've tested against Python versions
Kevin> 2.7.15, 2.7.17, 2.7.18, 3.7.7, 3.8.2, and 3.8.3.  In each case GDB
Kevin> still builds without problem and shows no regressions after applying
Kevin> this patch.

Nice.

Kevin>    /* Release the GIL while gdb runs.  */
Kevin> +#if PY_VERSION_HEX < 0x03090000
Kevin>    PyThreadState_Swap (NULL);
Kevin>    PyEval_ReleaseLock ();
Kevin> +#else
Kevin> +  PyEval_SaveThread ();
Kevin> +#endif
 
I tend to think we could use PyEval_SaveThread in all cases.

Tom

  reply	other threads:[~2020-05-28 14:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28  4:45 Kevin Buettner
2020-05-28 14:54 ` Tom Tromey [this message]
2020-05-28 17:42   ` Kevin Buettner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d06ohzzf.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).