@@ -56,19 +56,14 @@ macro_rules! assert_check_only {
5656
5757// Because of the relase pool unsoundness reported in https://github.com/PyO3/pyo3/issues/756,
5858// we need to stop other threads before calling `py.import()`.
59- // TODO(kngwyu): Remove this macro
60- macro_rules! lock {
61- ( ) => {
62- let _mutex = std:: sync:: Mutex :: new( ( ) ) ;
63- let _lock = _mutex. lock( ) . unwrap( ) ;
64- } ;
65- }
59+ // TODO(kngwyu): Remove this variable
60+ static MUTEX : parking_lot:: Mutex < ( ) > = parking_lot:: const_mutex ( ( ) ) ;
6661
6762#[ test]
6863fn test_date_check ( ) {
64+ let _lock = MUTEX . lock ( ) ;
6965 let gil = Python :: acquire_gil ( ) ;
7066 let py = gil. python ( ) ;
71- lock ! ( ) ;
7267 let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "date" , "2018, 1, 1" ) . unwrap ( ) ;
7368
7469 assert_check_exact ! ( PyDate_Check , obj) ;
@@ -78,9 +73,9 @@ fn test_date_check() {
7873
7974#[ test]
8075fn test_time_check ( ) {
76+ let _lock = MUTEX . lock ( ) ;
8177 let gil = Python :: acquire_gil ( ) ;
8278 let py = gil. python ( ) ;
83- lock ! ( ) ;
8479 let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "time" , "12, 30, 15" ) . unwrap ( ) ;
8580
8681 assert_check_exact ! ( PyTime_Check , obj) ;
@@ -90,9 +85,9 @@ fn test_time_check() {
9085
9186#[ test]
9287fn test_datetime_check ( ) {
88+ let _lock = MUTEX . lock ( ) ;
9389 let gil = Python :: acquire_gil ( ) ;
9490 let py = gil. python ( ) ;
95- lock ! ( ) ;
9691 let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "datetime" , "2018, 1, 1, 13, 30, 15" )
9792 . map_err ( |e| e. print ( py) )
9893 . unwrap ( ) ;
@@ -105,9 +100,9 @@ fn test_datetime_check() {
105100
106101#[ test]
107102fn test_delta_check ( ) {
103+ let _lock = MUTEX . lock ( ) ;
108104 let gil = Python :: acquire_gil ( ) ;
109105 let py = gil. python ( ) ;
110- lock ! ( ) ;
111106 let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "timedelta" , "1, -3" ) . unwrap ( ) ;
112107
113108 assert_check_exact ! ( PyDelta_Check , obj) ;
@@ -120,9 +115,9 @@ fn test_datetime_utc() {
120115 use assert_approx_eq:: assert_approx_eq;
121116 use pyo3:: types:: PyDateTime ;
122117
118+ let _lock = MUTEX . lock ( ) ;
123119 let gil = Python :: acquire_gil ( ) ;
124120 let py = gil. python ( ) ;
125- lock ! ( ) ;
126121 let datetime = py. import ( "datetime" ) . map_err ( |e| e. print ( py) ) . unwrap ( ) ;
127122 let timezone = datetime. get ( "timezone" ) . unwrap ( ) ;
128123 let utc = timezone. getattr ( "utc" ) . unwrap ( ) . to_object ( py) ;
0 commit comments