@@ -29,7 +29,7 @@ fn json<'a>(py: Python<'a>, code: &'a str) -> Bound<'a, PyAny> {
2929
3030#[ bench]
3131fn ints_json ( bench : & mut Bencher ) {
32- Python :: with_gil ( |py| {
32+ Python :: attach ( |py| {
3333 let validator = build_schema_validator ( py, c"{'type': 'int'}" ) ;
3434
3535 let result = validator
@@ -50,7 +50,7 @@ fn ints_json(bench: &mut Bencher) {
5050
5151#[ bench]
5252fn ints_python ( bench : & mut Bencher ) {
53- Python :: with_gil ( |py| {
53+ Python :: attach ( |py| {
5454 let validator = build_schema_validator ( py, c"{'type': 'int'}" ) ;
5555
5656 let Ok ( input) = 123_i64 . into_pyobject ( py) ;
@@ -73,7 +73,7 @@ fn ints_python(bench: &mut Bencher) {
7373
7474#[ bench]
7575fn list_int_json ( bench : & mut Bencher ) {
76- Python :: with_gil ( |py| {
76+ Python :: attach ( |py| {
7777 let validator = build_schema_validator ( py, c"{'type': 'list', 'items_schema': {'type': 'int'}}" ) ;
7878 let code = format ! (
7979 "[{}]" ,
@@ -104,7 +104,7 @@ fn list_int_input(py: Python<'_>) -> (SchemaValidator, PyObject) {
104104
105105#[ bench]
106106fn list_int_python ( bench : & mut Bencher ) {
107- Python :: with_gil ( |py| {
107+ Python :: attach ( |py| {
108108 let ( validator, input) = list_int_input ( py) ;
109109 let input = black_box ( input. bind ( py) ) ;
110110 bench. iter ( || {
@@ -118,7 +118,7 @@ fn list_int_python(bench: &mut Bencher) {
118118
119119#[ bench]
120120fn list_int_python_isinstance ( bench : & mut Bencher ) {
121- Python :: with_gil ( |py| {
121+ Python :: attach ( |py| {
122122 let ( validator, input) = list_int_input ( py) ;
123123 let input = black_box ( input. bind ( py) ) ;
124124 let v = validator
@@ -137,7 +137,7 @@ fn list_int_python_isinstance(bench: &mut Bencher) {
137137
138138#[ bench]
139139fn list_error_json ( bench : & mut Bencher ) {
140- Python :: with_gil ( |py| {
140+ Python :: attach ( |py| {
141141 let validator = build_schema_validator ( py, c"{'type': 'list', 'items_schema': {'type': 'int'}}" ) ;
142142 let code = format ! (
143143 "[{}]" ,
@@ -195,7 +195,7 @@ fn list_error_python_input(py: Python<'_>) -> (SchemaValidator, PyObject) {
195195
196196#[ bench]
197197fn list_error_python ( bench : & mut Bencher ) {
198- Python :: with_gil ( |py| {
198+ Python :: attach ( |py| {
199199 let ( validator, input) = list_error_python_input ( py) ;
200200
201201 let input = black_box ( input. bind ( py) ) ;
@@ -212,7 +212,7 @@ fn list_error_python(bench: &mut Bencher) {
212212
213213#[ bench]
214214fn list_error_python_isinstance ( bench : & mut Bencher ) {
215- Python :: with_gil ( |py| {
215+ Python :: attach ( |py| {
216216 let ( validator, input) = list_error_python_input ( py) ;
217217 let input = black_box ( input. bind ( py) ) ;
218218 let r = validator
@@ -232,7 +232,7 @@ fn list_error_python_isinstance(bench: &mut Bencher) {
232232
233233#[ bench]
234234fn list_any_json ( bench : & mut Bencher ) {
235- Python :: with_gil ( |py| {
235+ Python :: attach ( |py| {
236236 let validator = build_schema_validator ( py, c"{'type': 'list'}" ) ;
237237 let code = format ! (
238238 "[{}]" ,
@@ -251,7 +251,7 @@ fn list_any_json(bench: &mut Bencher) {
251251
252252#[ bench]
253253fn list_any_python ( bench : & mut Bencher ) {
254- Python :: with_gil ( |py| {
254+ Python :: attach ( |py| {
255255 let validator = build_schema_validator ( py, c"{'type': 'list'}" ) ;
256256 let code = CString :: new ( format ! (
257257 "[{}]" ,
@@ -279,7 +279,7 @@ fn as_str(i: u8) -> String {
279279
280280#[ bench]
281281fn dict_json ( bench : & mut Bencher ) {
282- Python :: with_gil ( |py| {
282+ Python :: attach ( |py| {
283283 let validator = build_schema_validator (
284284 py,
285285 c"{'type': 'dict', 'keys_schema': {'type': 'str'}, 'values_schema': {'type': 'int'}}" ,
@@ -305,7 +305,7 @@ fn dict_json(bench: &mut Bencher) {
305305
306306#[ bench]
307307fn dict_python ( bench : & mut Bencher ) {
308- Python :: with_gil ( |py| {
308+ Python :: attach ( |py| {
309309 let validator = build_schema_validator (
310310 py,
311311 c"{'type': 'dict', 'keys_schema': {'type': 'str'}, 'values_schema': {'type': 'int'}}" ,
@@ -332,7 +332,7 @@ fn dict_python(bench: &mut Bencher) {
332332
333333#[ bench]
334334fn dict_value_error ( bench : & mut Bencher ) {
335- Python :: with_gil ( |py| {
335+ Python :: attach ( |py| {
336336 let validator = build_schema_validator (
337337 py,
338338 cr"{
@@ -378,7 +378,7 @@ fn dict_value_error(bench: &mut Bencher) {
378378
379379#[ bench]
380380fn typed_dict_json ( bench : & mut Bencher ) {
381- Python :: with_gil ( |py| {
381+ Python :: attach ( |py| {
382382 let validator = build_schema_validator (
383383 py,
384384 cr"{
@@ -413,7 +413,7 @@ fn typed_dict_json(bench: &mut Bencher) {
413413
414414#[ bench]
415415fn typed_dict_python ( bench : & mut Bencher ) {
416- Python :: with_gil ( |py| {
416+ Python :: attach ( |py| {
417417 let validator = build_schema_validator (
418418 py,
419419 cr"{
@@ -448,7 +448,7 @@ fn typed_dict_python(bench: &mut Bencher) {
448448
449449#[ bench]
450450fn typed_dict_deep_error ( bench : & mut Bencher ) {
451- Python :: with_gil ( |py| {
451+ Python :: attach ( |py| {
452452 let validator = build_schema_validator (
453453 py,
454454 cr"{
@@ -504,7 +504,7 @@ fn typed_dict_deep_error(bench: &mut Bencher) {
504504
505505#[ bench]
506506fn complete_model ( bench : & mut Bencher ) {
507- Python :: with_gil ( |py| {
507+ Python :: attach ( |py| {
508508 let sys_path = py. import ( "sys" ) . unwrap ( ) . getattr ( "path" ) . unwrap ( ) ;
509509 sys_path. call_method1 ( "append" , ( "./tests/benchmarks/" , ) ) . unwrap ( ) ;
510510
@@ -527,7 +527,7 @@ fn complete_model(bench: &mut Bencher) {
527527
528528#[ bench]
529529fn nested_model_using_definitions ( bench : & mut Bencher ) {
530- Python :: with_gil ( |py| {
530+ Python :: attach ( |py| {
531531 let sys_path = py. import ( "sys" ) . unwrap ( ) . getattr ( "path" ) . unwrap ( ) ;
532532 sys_path. call_method1 ( "append" , ( "./tests/benchmarks/" , ) ) . unwrap ( ) ;
533533
@@ -554,7 +554,7 @@ fn nested_model_using_definitions(bench: &mut Bencher) {
554554
555555#[ bench]
556556fn nested_model_inlined ( bench : & mut Bencher ) {
557- Python :: with_gil ( |py| {
557+ Python :: attach ( |py| {
558558 let sys_path = py. import ( "sys" ) . unwrap ( ) . getattr ( "path" ) . unwrap ( ) ;
559559 sys_path. call_method1 ( "append" , ( "./tests/benchmarks/" , ) ) . unwrap ( ) ;
560560
@@ -581,7 +581,7 @@ fn nested_model_inlined(bench: &mut Bencher) {
581581
582582#[ bench]
583583fn literal_ints_few_python ( bench : & mut Bencher ) {
584- Python :: with_gil ( |py| {
584+ Python :: attach ( |py| {
585585 let validator = build_schema_validator ( py, c"{'type': 'literal', 'expected': list(range(5))}" ) ;
586586
587587 let Ok ( input) = 4_i64 . into_pyobject ( py) ;
@@ -604,7 +604,7 @@ fn literal_ints_few_python(bench: &mut Bencher) {
604604
605605#[ bench]
606606fn literal_strings_few_small_python ( bench : & mut Bencher ) {
607- Python :: with_gil ( |py| {
607+ Python :: attach ( |py| {
608608 let validator = build_schema_validator ( py, c"{'type': 'literal', 'expected': [f'{idx}' for idx in range(5)]}" ) ;
609609
610610 let input = py. eval ( c"'4'" , None , None ) . unwrap ( ) ;
@@ -628,7 +628,7 @@ fn literal_strings_few_small_python(bench: &mut Bencher) {
628628
629629#[ bench]
630630fn literal_strings_few_large_python ( bench : & mut Bencher ) {
631- Python :: with_gil ( |py| {
631+ Python :: attach ( |py| {
632632 let validator = build_schema_validator (
633633 py,
634634 c"{'type': 'literal', 'expected': ['a' * 25 + f'{idx}' for idx in range(5)]}" ,
@@ -655,7 +655,7 @@ fn literal_strings_few_large_python(bench: &mut Bencher) {
655655
656656#[ bench]
657657fn literal_enums_few_python ( bench : & mut Bencher ) {
658- Python :: with_gil ( |py| {
658+ Python :: attach ( |py| {
659659 let globals = PyDict :: new ( py) ;
660660 py. run (
661661 cr"
@@ -697,7 +697,7 @@ class Foo(Enum):
697697
698698#[ bench]
699699fn literal_ints_many_python ( bench : & mut Bencher ) {
700- Python :: with_gil ( |py| {
700+ Python :: attach ( |py| {
701701 let validator = build_schema_validator ( py, c"{'type': 'literal', 'expected': list(range(100))}" ) ;
702702
703703 let Ok ( input) = 99_i64 . into_pyobject ( py) ;
@@ -720,7 +720,7 @@ fn literal_ints_many_python(bench: &mut Bencher) {
720720
721721#[ bench]
722722fn literal_strings_many_small_python ( bench : & mut Bencher ) {
723- Python :: with_gil ( |py| {
723+ Python :: attach ( |py| {
724724 let validator =
725725 build_schema_validator ( py, c"{'type': 'literal', 'expected': [f'{idx}' for idx in range(100)]}" ) ;
726726
@@ -745,7 +745,7 @@ fn literal_strings_many_small_python(bench: &mut Bencher) {
745745
746746#[ bench]
747747fn literal_strings_many_large_python ( bench : & mut Bencher ) {
748- Python :: with_gil ( |py| {
748+ Python :: attach ( |py| {
749749 let validator = build_schema_validator (
750750 py,
751751 c"{'type': 'literal', 'expected': ['a' * 25 + f'{idx}' for idx in range(100)]}" ,
@@ -772,7 +772,7 @@ fn literal_strings_many_large_python(bench: &mut Bencher) {
772772
773773#[ bench]
774774fn literal_ints_many_json ( bench : & mut Bencher ) {
775- Python :: with_gil ( |py| {
775+ Python :: attach ( |py| {
776776 let validator = build_schema_validator ( py, c"{'type': 'literal', 'expected': list(range(100))}" ) ;
777777
778778 let input_json = py. eval ( c"'99'" , None , None ) . unwrap ( ) ;
@@ -795,7 +795,7 @@ fn literal_ints_many_json(bench: &mut Bencher) {
795795
796796#[ bench]
797797fn literal_strings_many_large_json ( bench : & mut Bencher ) {
798- Python :: with_gil ( |py| {
798+ Python :: attach ( |py| {
799799 let validator = build_schema_validator (
800800 py,
801801 c"{'type': 'literal', 'expected': ['a' * 25 + f'{idx}' for idx in range(100)]}" ,
@@ -823,7 +823,7 @@ fn literal_strings_many_large_json(bench: &mut Bencher) {
823823
824824#[ bench]
825825fn literal_mixed_few_python ( bench : & mut Bencher ) {
826- Python :: with_gil ( |py| {
826+ Python :: attach ( |py| {
827827 let globals = PyDict :: new ( py) ;
828828 py. run (
829829 cr"
0 commit comments