| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6172c79 commit 72d052e
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -182,18 +182,21 @@ public int XProp | |||
| 182 | 182 | { | |
| 183 | 183 | get | |
| 184 | 184 | { | |
| 185 | - using (var scope = Py.CreateScope()) | ||
| 185 | + using(Py.GIL()) | ||
| 186 | 186 | { | |
| 187 | - scope.Set("this", this); | ||
| 188 | - try | ||
| 187 | + using (var scope = Py.CreateScope()) | ||
| 189 | 188 | { | |
| 190 | - return scope.Eval<int>($"super(this.__class__, this).{nameof(XProp)}"); | ||
| 191 | - } | ||
| 192 | - catch (PythonException ex) when (PythonReferenceComparer.Instance.Equals(ex.Type, Exceptions.AttributeError)) | ||
| 193 | - { | ||
| 194 | - if (this.extras.TryGetValue(nameof(this.XProp), out object value)) | ||
| 195 | - return (int)value; | ||
| 196 | - throw; | ||
| 189 | + scope.Set("this", this); | ||
| 190 | + try | ||
| 191 | + { | ||
| 192 | + return scope.Eval<int>($"super(this.__class__, this).{nameof(XProp)}"); | ||
| 193 | + } | ||
| 194 | + catch (PythonException ex) when (PythonReferenceComparer.Instance.Equals(ex.Type, Exceptions.AttributeError)) | ||
| 195 | + { | ||
| 196 | + if (this.extras.TryGetValue(nameof(this.XProp), out object value)) | ||
| 197 | + return (int)value; | ||
| 198 | + throw; | ||
| 199 | + } | ||
| 197 | 200 | } | |
| 198 | 201 | } | |
| 199 | 202 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,16 +102,22 @@ public void TearDown() | |||
| 102 | 102 | /// https://quantconnect.slack.com/archives/G51920EN4/p1615418516028900 | |
| 103 | 103 | public void ParamTest() | |
| 104 | 104 | { | |
| 105 | - var output = (bool)module.TestA(); | ||
| 106 | - Assert.IsTrue(output); | ||
| 105 | + using (Py.GIL()) | ||
| 106 | + { | ||
| 107 | + var output = (bool)module.TestA(); | ||
| 108 | + Assert.IsTrue(output); | ||
| 109 | + } | ||
| 107 | 110 | } | |
| 108 | 111 | ||
| 109 | 112 | [TestCase("AAPL", false)] | |
| 110 | 113 | [TestCase("SPY", true)] | |
| 111 | 114 | public void ContainsTest(string key, bool expected) | |
| 112 | 115 | { | |
| 113 | 116 | var dic = new Dictionary<string, object> { { "SPY", new object() } }; | |
| 114 | - Assert.AreEqual(expected, (bool)containsTest(key, dic)); | ||
| 117 | + using (Py.GIL()) | ||
| 118 | + { | ||
| 119 | + Assert.AreEqual(expected, (bool)containsTest(key, dic)); | ||
| 120 | + } | ||
| 115 | 121 | } | |
| 116 | 122 | ||
| 117 | 123 | [Test] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,12 @@ public class TestUtil | |||
| 33 | 33 | [TestCase("PERatio10YearAverage", "pe_ratio_10_year_average")] | |
| 34 | 34 | [TestCase("CAPERatio", "cape_ratio")] | |
| 35 | 35 | [TestCase("EVToEBITDA3YearGrowth", "ev_to_ebitda_3_year_growth")] | |
| 36 | + [TestCase("EVToForwardEBITDA", "ev_to_forward_ebitda")] | ||
| 37 | + [TestCase("EVToRevenue", "ev_to_revenue")] | ||
| 38 | + [TestCase("EVToPreTaxIncome", "ev_to_pre_tax_income")] | ||
| 39 | + [TestCase("EVToTotalAssets", "ev_to_total_assets")] | ||
| 40 | + [TestCase("EVToFCF", "ev_to_fcf")] | ||
| 41 | + [TestCase("EVToEBIT", "ev_to_ebit")] | ||
| 36 | 42 | [TestCase("", "")] | |
| 37 | 43 | public void ConvertsNameToSnakeCase(string name, string expected) | |
| 38 | 44 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ | |||
| 13 | 13 | <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |
| 14 | 14 | </PackageReference> | |
| 15 | 15 | <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" /> | |
| 16 | - <PackageReference Include="quantconnect.pythonnet" Version="2.0.35" GeneratePathProperty="true"> | ||
| 16 | + <PackageReference Include="quantconnect.pythonnet" Version="2.0.36" GeneratePathProperty="true"> | ||
| 17 | 17 | <IncludeAssets>compile</IncludeAssets> | |
| 18 | 18 | </PackageReference> | |
| 19 | 19 | </ItemGroup> | |
@@ -25,7 +25,7 @@ | |||
| 25 | 25 | </Target> | |
| 26 | 26 | ||
| 27 | 27 | <Target Name="CopyBaseline" AfterTargets="Build"> | |
| 28 | - <Copy SourceFiles="$(NuGetPackageRoot)quantconnect.pythonnet\2.0.35\lib\net5.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" /> | ||
| 28 | + <Copy SourceFiles="$(NuGetPackageRoot)quantconnect.pythonnet\2.0.36\lib\net6.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" /> | ||
| 29 | 29 | </Target> | |
| 30 | 30 | ||
| 31 | 31 | <Target Name="CopyNewBuild" AfterTargets="Build"> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,5 +4,5 @@ | |||
| 4 | 4 | [assembly: InternalsVisibleTo("Python.EmbeddingTest, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")] | |
| 5 | 5 | [assembly: InternalsVisibleTo("Python.Test, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")] | |
| 6 | 6 | ||
| 7 | - [assembly: AssemblyVersion("2.0.35")] | ||
| 8 | - [assembly: AssemblyFileVersion("2.0.35")] | ||
| 7 | + [assembly: AssemblyVersion("2.0.36")] | ||
| 8 | + [assembly: AssemblyFileVersion("2.0.36")] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,12 +10,21 @@ namespace Python.Runtime; | |||
| 10 | 10 | ||
| 11 | 11 | public static class Py | |
| 12 | 12 | { | |
| 13 | + public static IDisposable AllowThreads() => new AllowThreadsState(); | ||
| 13 | 14 | public static GILState GIL() => PythonEngine.DebugGIL ? new DebugGILState() : new GILState(); | |
| 14 | 15 | ||
| 15 | 16 | public static PyModule CreateScope() => new(); | |
| 16 | 17 | public static PyModule CreateScope(string name) | |
| 17 | 18 | => new(name ?? throw new ArgumentNullException(nameof(name))); | |
| 18 | 19 | ||
| 20 | + public sealed class AllowThreadsState : IDisposable | ||
| 21 | + { | ||
| 22 | + private readonly IntPtr ts = PythonEngine.BeginAllowThreads(); | ||
| 23 | + public void Dispose() | ||
| 24 | + { | ||
| 25 | + PythonEngine.EndAllowThreads(ts); | ||
| 26 | + } | ||
| 27 | + } | ||
| 19 | 28 | ||
| 20 | 29 | public class GILState : IDisposable | |
| 21 | 30 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | <RootNamespace>Python.Runtime</RootNamespace> | |
| 6 | 6 | <AssemblyName>Python.Runtime</AssemblyName> | |
| 7 | 7 | <PackageId>QuantConnect.pythonnet</PackageId> | |
| 8 | - <Version>2.0.35</Version> | ||
| 8 | + <Version>2.0.36</Version> | ||
| 9 | 9 | <GenerateAssemblyInfo>false</GenerateAssemblyInfo> | |
| 10 | 10 | <PackageLicenseFile>LICENSE</PackageLicenseFile> | |
| 11 | 11 | <RepositoryUrl>https://github.com/pythonnet/pythonnet</RepositoryUrl> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,11 +64,18 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference | |||
| 64 | 64 | // Fasterflect does not support constant fields | |
| 65 | 65 | if (info.IsLiteral && !info.IsInitOnly) | |
| 66 | 66 | { | |
| 67 | - result = info.GetValue(null); | ||
| 67 | + using (Py.AllowThreads()) | ||
| 68 | + { | ||
| 69 | + result = info.GetValue(null); | ||
| 70 | + } | ||
| 68 | 71 | } | |
| 69 | 72 | else | |
| 70 | 73 | { | |
| 71 | - result = self.GetMemberGetter(info.DeclaringType)(info.DeclaringType); | ||
| 74 | + var getter = self.GetMemberGetter(info.DeclaringType); | ||
| 75 | + using (Py.AllowThreads()) | ||
| 76 | + { | ||
| 77 | + result = getter(info.DeclaringType); | ||
| 78 | + } | ||
| 72 | 79 | } | |
| 73 | 80 | ||
| 74 | 81 | return Converter.ToPython(result, info.FieldType); | |
@@ -92,12 +99,20 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference | |||
| 92 | 99 | // Fasterflect does not support constant fields | |
| 93 | 100 | if (info.IsLiteral && !info.IsInitOnly) | |
| 94 | 101 | { | |
| 95 | - result = info.GetValue(co.inst); | ||
| 102 | + using (Py.AllowThreads()) | ||
| 103 | + { | ||
| 104 | + result = info.GetValue(co.inst); | ||
| 105 | + } | ||
| 96 | 106 | } | |
| 97 | 107 | else | |
| 98 | 108 | { | |
| 99 | 109 | var type = co.inst.GetType(); | |
| 100 | - result = self.GetMemberGetter(type)(self.IsValueType(type) ? co.inst.WrapIfValueType() : co.inst); | ||
| 110 | + var getter = self.GetMemberGetter(type); | ||
| 111 | + var argument = self.IsValueType(type) ? co.inst.WrapIfValueType() : co.inst; | ||
| 112 | + using (Py.AllowThreads()) | ||
| 113 | + { | ||
| 114 | + result = getter(argument); | ||
| 115 | + } | ||
| 101 | 116 | } | |
| 102 | 117 | ||
| 103 | 118 | return Converter.ToPython(result, info.FieldType); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,11 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference | |||
| 76 | 76 | ||
| 77 | 77 | try | |
| 78 | 78 | { | |
| 79 | - result = self.GetMemberGetter(info.DeclaringType)(info.DeclaringType); | ||
| 79 | + var getterFunc = self.GetMemberGetter(info.DeclaringType); | ||
| 80 | + using (Py.AllowThreads()) | ||
| 81 | + { | ||
| 82 | + result = getterFunc(info.DeclaringType); | ||
| 83 | + } | ||
| 80 | 84 | return Converter.ToPython(result, info.PropertyType); | |
| 81 | 85 | } | |
| 82 | 86 | catch (Exception e) | |
@@ -93,7 +97,10 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference | |||
| 93 | 97 | ||
| 94 | 98 | try | |
| 95 | 99 | { | |
| 96 | - result = getter.Invoke(co.inst, Array.Empty<object>()); | ||
| 100 | + using (Py.AllowThreads()) | ||
| 101 | + { | ||
| 102 | + result = getter.Invoke(co.inst, Array.Empty<object>()); | ||
| 103 | + } | ||
| 97 | 104 | return Converter.ToPython(result, info.PropertyType); | |
| 98 | 105 | } | |
| 99 | 106 | catch (Exception e) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments