@@ -24,7 +24,7 @@ interpreter. For example:
24
24
static int
25
25
thread_function(PyInterpreterView view)
26
26
{
27
- PyInterpreterLock lock = PyInterpreterLock_AcquireView (view);
27
+ PyInterpreterLock lock = PyInterpreterLock_FromView (view);
28
28
if (lock == 0) {
29
29
return -1;
30
30
}
@@ -300,7 +300,7 @@ Interpreter Locks
300
300
301
301
This type is guaranteed to be pointer-sized.
302
302
303
- .. c :function :: PyInterpreterLock PyInterpreterLock_AcquireCurrent (void)
303
+ .. c :function :: PyInterpreterLock PyInterpreterLock_FromCurrent (void)
304
304
305
305
Acquire a lock for the current interpreter.
306
306
@@ -310,7 +310,7 @@ Interpreter Locks
310
310
The caller must hold an :term:`attached thread state`.
311
311
312
312
313
- .. c:function:: PyInterpreterLock PyInterpreterLock_AcquireView (PyInterpreterView view)
313
+ .. c:function:: PyInterpreterLock PyInterpreterLock_FromView (PyInterpreterView view)
314
314
315
315
Acquire a lock to an interpreter through a view.
316
316
@@ -364,7 +364,7 @@ Interpreter Views
364
364
Create a view to the current interpreter.
365
365
366
366
This function is generally meant to be used in tandem with
367
- :c:func:`PyInterpreterLock_AcquireView `.
367
+ :c:func:`PyInterpreterLock_FromView `.
368
368
369
369
On success, this function returns a view to the current
370
370
interpreter, and returns ``0`` with an exception set on failure.
@@ -402,7 +402,7 @@ Interpreter Views
402
402
The caller does not need to hold an :term:`attached thread state`.
403
403
404
404
405
- Ensuring And Releasing Thread States
405
+ Ensuring and Releasing Thread States
406
406
------------------------------------
407
407
408
408
This proposal includes two new high-level threading APIs that intend to
@@ -508,7 +508,7 @@ With this PEP, you would implement it like this:
508
508
PyObject *file,
509
509
PyObject *text)
510
510
{
511
- PyInterpreterLock lock = PyInterpreterLock_AcquireView (view);
511
+ PyInterpreterLock lock = PyInterpreterLock_FromView (view);
512
512
if (lock == 0) {
513
513
/ * Python interpreter has shut down */
514
514
return -1;
@@ -556,7 +556,7 @@ held. Any future finalizer that attempted to acquire the lock would be deadlocke
556
556
my_critical_operation(PyObject *self, PyObject *Py_UNUSED(args))
557
557
{
558
558
assert(PyThreadState_GetUnchecked() != NULL);
559
- PyInterpreterLock lock = PyInterpreterLock_AcquireCurrent ();
559
+ PyInterpreterLock lock = PyInterpreterLock_FromCurrent ();
560
560
if (lock == 0) {
561
561
/* Python interpreter has shut down */
562
562
return NULL;
@@ -639,7 +639,7 @@ This is the same code, rewritten to use the new functions:
639
639
PyThread_handle_t handle;
640
640
PyThead_indent_t indent;
641
641
642
- PyInterpreterLock lock = PyInterpreterLock_AcquireCurrent ();
642
+ PyInterpreterLock lock = PyInterpreterLock_FromCurrent ();
643
643
if (lock == 0) {
644
644
return NULL;
645
645
}
@@ -690,7 +690,7 @@ hang the current thread forever).
690
690
PyThread_handle_t handle;
691
691
PyThead_indent_t indent;
692
692
693
- PyInterpreterLock lock = PyInterpreterLock_AcquireCurrent ();
693
+ PyInterpreterLock lock = PyInterpreterLock_FromCurrent ();
694
694
if (lock == 0) {
695
695
return NULL;
696
696
}
@@ -716,7 +716,7 @@ Example: An Asynchronous Callback
716
716
{
717
717
ThreadData *tdata = (ThreadData *)arg;
718
718
PyInterpreterView view = tdata->view;
719
- PyInterpreterLock lock = PyInterpreterLock_AcquireView (view);
719
+ PyInterpreterLock lock = PyInterpreterLock_FromView (view);
720
720
if (lock == 0) {
721
721
fputs("Python has shut down!\n", stderr);
722
722
return -1;
@@ -771,7 +771,13 @@ interpreter through :c:func:`PyUnstable_InterpreterView_FromDefault`.
771
771
static void
772
772
call_python(void)
773
773
{
774
- PyInterpreterLock lock = PyUnstable_InterpreterView_FromDefault();
774
+ PyInterpreterView view = PyUnstable_InterpreterView_FromDefault();
775
+ if (lock == 0) {
776
+ fputs("Python has shut down.", stderr);
777
+ return;
778
+ }
779
+
780
+ PyInterpreterLock lock = PyInterpreterLock_FromView(view);
775
781
if (lock == 0) {
776
782
fputs("Python has shut down.", stderr);
777
783
return;
@@ -780,13 +786,15 @@ interpreter through :c:func:`PyUnstable_InterpreterView_FromDefault`.
780
786
PyThreadView thread_view = PyThreadState_Ensure(lock);
781
787
if (thread_view == 0) {
782
788
PyInterpreterLock_Release(lock);
789
+ PyInterpreterView_Close(view);
783
790
return -1;
784
791
}
785
792
if (PyRun_SimpleString("print(42)") < 0) {
786
793
PyErr_Print();
787
794
}
788
795
PyThreadState_Release(thread_view);
789
796
PyInterpreterLock_Release(lock);
797
+ PyInterpreterView_Close(view);
790
798
return 0;
791
799
}
792
800
0 commit comments