Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
2f828f2c
Kaydet (Commit)
2f828f2c
authored
Ock 17, 2012
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Test running of code in a sub-interpreter
(prelude to issue #6531).
üst
03757ec4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
test_capi.py
Lib/test/test_capi.py
+17
-0
_testcapimodule.c
Modules/_testcapimodule.c
+27
-0
No files found.
Lib/test/test_capi.py
Dosyayı görüntüle @
2f828f2c
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
from
__future__
import
with_statement
from
__future__
import
with_statement
import
os
import
os
import
pickle
import
random
import
random
import
subprocess
import
subprocess
import
sys
import
sys
...
@@ -137,6 +138,22 @@ class TestPendingCalls(unittest.TestCase):
...
@@ -137,6 +138,22 @@ class TestPendingCalls(unittest.TestCase):
self
.
pendingcalls_submit
(
l
,
n
)
self
.
pendingcalls_submit
(
l
,
n
)
self
.
pendingcalls_wait
(
l
,
n
)
self
.
pendingcalls_wait
(
l
,
n
)
def
test_subinterps
(
self
):
# XXX this test leaks in refleak runs
import
builtins
r
,
w
=
os
.
pipe
()
code
=
"""if 1:
import sys, builtins, pickle
with open({:d}, "wb") as f:
pickle.dump(id(sys.modules), f)
pickle.dump(id(builtins), f)
"""
.
format
(
w
)
with
open
(
r
,
"rb"
)
as
f
:
ret
=
_testcapi
.
run_in_subinterp
(
code
)
self
.
assertEqual
(
ret
,
0
)
self
.
assertNotEqual
(
pickle
.
load
(
f
),
id
(
sys
.
modules
))
self
.
assertNotEqual
(
pickle
.
load
(
f
),
id
(
builtins
))
# Bug #6012
# Bug #6012
class
Test6012
(
unittest
.
TestCase
):
class
Test6012
(
unittest
.
TestCase
):
def
test
(
self
):
def
test
(
self
):
...
...
Modules/_testcapimodule.c
Dosyayı görüntüle @
2f828f2c
...
@@ -2300,6 +2300,32 @@ crash_no_current_thread(PyObject *self)
...
@@ -2300,6 +2300,32 @@ crash_no_current_thread(PyObject *self)
return
NULL
;
return
NULL
;
}
}
/* To run some code in a sub-interpreter. */
static
PyObject
*
run_in_subinterp
(
PyObject
*
self
,
PyObject
*
args
)
{
const
char
*
code
;
int
r
;
PyThreadState
*
substate
,
*
mainstate
;
if
(
!
PyArg_ParseTuple
(
args
,
"s:run_in_subinterp"
,
&
code
))
return
NULL
;
mainstate
=
PyThreadState_Get
();
PyThreadState_Swap
(
NULL
);
substate
=
Py_NewInterpreter
();
r
=
PyRun_SimpleString
(
code
);
Py_EndInterpreter
(
substate
);
PyThreadState_Swap
(
mainstate
);
return
PyLong_FromLong
(
r
);
}
static
PyMethodDef
TestMethods
[]
=
{
static
PyMethodDef
TestMethods
[]
=
{
{
"raise_exception"
,
raise_exception
,
METH_VARARGS
},
{
"raise_exception"
,
raise_exception
,
METH_VARARGS
},
{
"raise_memoryerror"
,
(
PyCFunction
)
raise_memoryerror
,
METH_NOARGS
},
{
"raise_memoryerror"
,
(
PyCFunction
)
raise_memoryerror
,
METH_NOARGS
},
...
@@ -2385,6 +2411,7 @@ static PyMethodDef TestMethods[] = {
...
@@ -2385,6 +2411,7 @@ static PyMethodDef TestMethods[] = {
{
"make_memoryview_from_NULL_pointer"
,
(
PyCFunction
)
make_memoryview_from_NULL_pointer
,
{
"make_memoryview_from_NULL_pointer"
,
(
PyCFunction
)
make_memoryview_from_NULL_pointer
,
METH_NOARGS
},
METH_NOARGS
},
{
"crash_no_current_thread"
,
(
PyCFunction
)
crash_no_current_thread
,
METH_NOARGS
},
{
"crash_no_current_thread"
,
(
PyCFunction
)
crash_no_current_thread
,
METH_NOARGS
},
{
"run_in_subinterp"
,
run_in_subinterp
,
METH_VARARGS
},
{
NULL
,
NULL
}
/* sentinel */
{
NULL
,
NULL
}
/* sentinel */
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment