@@ -1056,6 +1056,7 @@ public PyList Dir()
10561056/// </remarks>
10571057public override string ? ToString ( )
10581058{
1059+ using var _ = Py . GIL ( ) ;
10591060using var strval = Runtime . PyObject_Str ( obj ) ;
10601061return Runtime . GetManagedString ( strval . BorrowOrThrow ( ) ) ;
10611062}
@@ -1072,7 +1073,11 @@ public PyList Dir()
10721073/// Return true if this object is equal to the given object. This
10731074/// method is based on Python equality semantics.
10741075/// </remarks>
1075- public override bool Equals ( object o ) => Equals ( o as PyObject ) ;
1076+ public override bool Equals ( object o )
1077+ {
1078+ using var _ = Py . GIL ( ) ;
1079+ return Equals ( o as PyObject ) ;
1080+ }
10761081
10771082public virtual bool Equals ( PyObject ? other )
10781083{
@@ -1101,6 +1106,7 @@ public virtual bool Equals(PyObject? other)
11011106/// </remarks>
11021107public override int GetHashCode ( )
11031108{
1109+ using var _ = Py . GIL ( ) ;
11041110nint pyHash = Runtime . PyObject_Hash ( obj ) ;
11051111if ( pyHash == - 1 && Exceptions . ErrorOccurred ( ) )
11061112{
@@ -1135,12 +1141,14 @@ public long Refcount
11351141
11361142public override bool TryGetMember ( GetMemberBinder binder , out object ? result )
11371143{
1144+ using var _ = Py . GIL ( ) ;
11381145result = CheckNone ( this . GetAttr ( binder . Name ) ) ;
11391146return true ;
11401147}
11411148
11421149public override bool TrySetMember ( SetMemberBinder binder , object ? value )
11431150{
1151+ using var _ = Py . GIL ( ) ;
11441152using var newVal = Converter . ToPythonDetectType ( value ) ;
11451153int r = Runtime . PyObject_SetAttrString ( obj , binder . Name , newVal . Borrow ( ) ) ;
11461154if ( r < 0 )
@@ -1234,6 +1242,7 @@ private static NewReference GetPythonObject(object? target)
12341242
12351243public override bool TryInvokeMember ( InvokeMemberBinder binder , object ? [ ] args , out object ? result )
12361244{
1245+ using var _ = Py . GIL ( ) ;
12371246if ( this . HasAttr ( binder . Name ) && this . GetAttr ( binder . Name ) . IsCallable ( ) )
12381247{
12391248PyTuple ? pyargs = null ;
@@ -1258,6 +1267,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object?[] args,
12581267
12591268public override bool TryInvoke ( InvokeBinder binder , object ? [ ] args , out object ? result )
12601269{
1270+ using var _ = Py . GIL ( ) ;
12611271if ( this . IsCallable ( ) )
12621272{
12631273PyTuple ? pyargs = null ;
@@ -1282,6 +1292,7 @@ public override bool TryInvoke(InvokeBinder binder, object?[] args, out object?
12821292
12831293public override bool TryConvert ( ConvertBinder binder , out object ? result )
12841294{
1295+ using var _ = Py . GIL ( ) ;
12851296// always try implicit conversion first
12861297if ( Converter . ToManaged ( this . obj , binder . Type , out result , false ) )
12871298{
@@ -1307,6 +1318,7 @@ public override bool TryConvert(ConvertBinder binder, out object? result)
13071318
13081319public override bool TryBinaryOperation ( BinaryOperationBinder binder , object arg , out object ? result )
13091320{
1321+ using var _ = Py . GIL ( ) ;
13101322NewReference res ;
13111323if ( ! ( arg is PyObject ) )
13121324{
@@ -1419,6 +1431,7 @@ public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg
14191431
14201432public override bool TryUnaryOperation ( UnaryOperationBinder binder , out object ? result )
14211433{
1434+ using var _ = Py . GIL ( ) ;
14221435int r ;
14231436NewReference res ;
14241437switch ( binder . Operation )
@@ -1463,10 +1476,8 @@ public override bool TryUnaryOperation(UnaryOperationBinder binder, out object?
14631476/// <returns>A sequence that contains dynamic member names.</returns>
14641477public override IEnumerable < string > GetDynamicMemberNames ( )
14651478{
1466- foreach ( PyObject pyObj in Dir ( ) )
1467- {
1468- yield return pyObj . ToString ( ) ! ;
1469- }
1479+ using var _ = Py . GIL ( ) ;
1480+ return Dir ( ) . Select ( pyObj=> pyObj . ToString ( ) ! ) . ToArray ( ) ;
14701481}
14711482
14721483void ISerializable . GetObjectData ( SerializationInfo info , StreamingContext context )