@@ -56,19 +56,14 @@ macro_rules! assert_check_only {
56
56
57
57
// Because of the relase pool unsoundness reported in https://github.com/PyO3/pyo3/issues/756,
58
58
// 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 ( ( ) ) ;
66
61
67
62
#[ test]
68
63
fn test_date_check ( ) {
64
+ let _lock = MUTEX . lock ( ) ;
69
65
let gil = Python :: acquire_gil ( ) ;
70
66
let py = gil. python ( ) ;
71
- lock ! ( ) ;
72
67
let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "date" , "2018, 1, 1" ) . unwrap ( ) ;
73
68
74
69
assert_check_exact ! ( PyDate_Check , obj) ;
@@ -78,9 +73,9 @@ fn test_date_check() {
78
73
79
74
#[ test]
80
75
fn test_time_check ( ) {
76
+ let _lock = MUTEX . lock ( ) ;
81
77
let gil = Python :: acquire_gil ( ) ;
82
78
let py = gil. python ( ) ;
83
- lock ! ( ) ;
84
79
let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "time" , "12, 30, 15" ) . unwrap ( ) ;
85
80
86
81
assert_check_exact ! ( PyTime_Check , obj) ;
@@ -90,9 +85,9 @@ fn test_time_check() {
90
85
91
86
#[ test]
92
87
fn test_datetime_check ( ) {
88
+ let _lock = MUTEX . lock ( ) ;
93
89
let gil = Python :: acquire_gil ( ) ;
94
90
let py = gil. python ( ) ;
95
- lock ! ( ) ;
96
91
let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "datetime" , "2018, 1, 1, 13, 30, 15" )
97
92
. map_err ( |e| e. print ( py) )
98
93
. unwrap ( ) ;
@@ -105,9 +100,9 @@ fn test_datetime_check() {
105
100
106
101
#[ test]
107
102
fn test_delta_check ( ) {
103
+ let _lock = MUTEX . lock ( ) ;
108
104
let gil = Python :: acquire_gil ( ) ;
109
105
let py = gil. python ( ) ;
110
- lock ! ( ) ;
111
106
let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "timedelta" , "1, -3" ) . unwrap ( ) ;
112
107
113
108
assert_check_exact ! ( PyDelta_Check , obj) ;
@@ -120,9 +115,9 @@ fn test_datetime_utc() {
120
115
use assert_approx_eq:: assert_approx_eq;
121
116
use pyo3:: types:: PyDateTime ;
122
117
118
+ let _lock = MUTEX . lock ( ) ;
123
119
let gil = Python :: acquire_gil ( ) ;
124
120
let py = gil. python ( ) ;
125
- lock ! ( ) ;
126
121
let datetime = py. import ( "datetime" ) . map_err ( |e| e. print ( py) ) . unwrap ( ) ;
127
122
let timezone = datetime. get ( "timezone" ) . unwrap ( ) ;
128
123
let utc = timezone. getattr ( "utc" ) . unwrap ( ) . to_object ( py) ;
0 commit comments