FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Removed deadlock if property setter or getter callback into Python. · pythonnet/pythonnet@bb1924d · GitHub

Repository navigation

Commit bb1924d

Browse files
committed
Removed deadlock if property setter or getter callback into Python.
1 parent 8a9fd73 commit bb1924d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎src/runtime/propertyobject.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
3333
MethodInfo getter = self.getter;
3434
object result;
3535

36+
IntPtr ts = IntPtr.Zero;
3637

3738
if (getter == null)
3839
{
@@ -48,13 +49,16 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
4849
return IntPtr.Zero;
4950
}
5051

52+
ts = PythonEngine.BeginAllowThreads();
5153
try
5254
{
5355
result = self.info.GetValue(null, null);
56+
PythonEngine.EndAllowThreads(ts);
5457
return Converter.ToPython(result, self.info.PropertyType);
5558
}
5659
catch (Exception e)
5760
{
61+
PythonEngine.EndAllowThreads(ts);
5862
return Exceptions.RaiseTypeError(e.Message);
5963
}
6064
}
@@ -65,9 +69,11 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
6569
return Exceptions.RaiseTypeError("invalid target");
6670
}
6771

72+
ts = PythonEngine.BeginAllowThreads();
6873
try
6974
{
7075
result = self.info.GetValue(co.inst, null);
76+
PythonEngine.EndAllowThreads(ts);
7177
return Converter.ToPython(result, self.info.PropertyType);
7278
}
7379
catch (Exception e)
@@ -76,6 +82,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
7682
{
7783
e = e.InnerException;
7884
}
85+
PythonEngine.EndAllowThreads(ts);
7986
Exceptions.SetError(e);
8087
return IntPtr.Zero;
8188
}
@@ -92,6 +99,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
9299
var self = (PropertyObject)GetManagedObject(ds);
93100
MethodInfo setter = self.setter;
94101
object newval;
102+
IntPtr ts = IntPtr.Zero;
95103

96104
if (val == IntPtr.Zero)
97105
{
@@ -132,12 +140,15 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
132140
Exceptions.RaiseTypeError("invalid target");
133141
return -1;
134142
}
143+
ts = PythonEngine.BeginAllowThreads();
135144
self.info.SetValue(co.inst, newval, null);
136145
}
137146
else
138147
{
148+
ts = PythonEngine.BeginAllowThreads();
139149
self.info.SetValue(null, newval, null);
140150
}
151+
PythonEngine.EndAllowThreads(ts);
141152
return 0;
142153
}
143154
catch (Exception e)
@@ -146,6 +157,11 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
146157
{
147158
e = e.InnerException;
148159
}
160+
161+
if (IntPtr.Zero != ts)
162+
{
163+
PythonEngine.EndAllowThreads(ts);
164+
}
149165
Exceptions.SetError(e);
150166
return -1;
151167
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL