Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions DSPythonNet3/DSPythonNet3Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
internal class DynamoCPythonHandleComparer : IEqualityComparer<DynamoCPythonHandle>
{

public bool Equals(DynamoCPythonHandle x, DynamoCPythonHandle y)

Check warning on line 23 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Nullability of reference types in type of parameter 'y' of 'bool DynamoCPythonHandleComparer.Equals(DynamoCPythonHandle x, DynamoCPythonHandle y)' doesn't match implicitly implemented member 'bool IEqualityComparer<DynamoCPythonHandle>.Equals(DynamoCPythonHandle? x, DynamoCPythonHandle? y)' (possibly because of nullability attributes).

Check warning on line 23 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Nullability of reference types in type of parameter 'x' of 'bool DynamoCPythonHandleComparer.Equals(DynamoCPythonHandle x, DynamoCPythonHandle y)' doesn't match implicitly implemented member 'bool IEqualityComparer<DynamoCPythonHandle>.Equals(DynamoCPythonHandle? x, DynamoCPythonHandle? y)' (possibly because of nullability attributes).
{
return x.PythonObjectID.Equals(y.PythonObjectID);
}
Expand Down Expand Up @@ -74,7 +74,7 @@
try
{
var pyobj = DSPythonNet3Evaluator.globalScope.Get(PythonObjectID.ToString());
return pyobj.ToString();

Check warning on line 77 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Possible null reference return.
}
catch (Exception e)
{
Expand Down Expand Up @@ -143,8 +143,8 @@
{ // Session is null when running unit tests.
if (ExecutionEvents.ActiveSession != null)
{
dynamoLogger = ExecutionEvents.ActiveSession.GetParameterValue(ParameterKeys.Logger) as DynamoLogger;

Check warning on line 146 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Possible null reference assignment.
return dynamoLogger;

Check warning on line 147 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Possible null reference return.
}
return dynamoLogger;
}
Expand All @@ -165,9 +165,10 @@
/// </summary>
internal static DSPythonNet3Evaluator Instance { get { return lazy.Value; } }

static DSPythonNet3Evaluator()

Check warning on line 168 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Non-nullable field 'path' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 168 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Non-nullable field 'dynamoLogger' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 168 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Non-nullable field 'globalScope' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
InitializeEncoders();
SubscribeToDynamoResetEvent();

var dynamoRevitAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name == "DynamoRevitDS");

Expand All @@ -177,14 +178,38 @@
}
}

/// <summary>
/// Subscribes our handler to DynamoModel.RequestPythonReset (internal static event) using reflection.
/// </summary>
private static void SubscribeToDynamoResetEvent()
{
try
{
var dmType = typeof(Dynamo.Models.DynamoModel);

// internal static event Action<string> RequestPythonReset;
var evt = dmType.GetEvent("RequestPythonReset",
BindingFlags.Static | BindingFlags.NonPublic);
if (evt == null) return;

// get the non-public "add" method and hook our Action<string>
var addMethod = evt.GetAddMethod(true);
if (addMethod == null) return;

Action<string> handler = RequestPythonResetHandler;
addMethod.Invoke(null, new object[] { handler });
}
catch { }
}

public override string Name => "PythonNet3";

internal static void RequestPythonResetHandler(string pythonEngine)
{
//check if python engine request is for this engine, and engine is currently started
if (PythonEngine.IsInitialized && pythonEngine == Instance.Name)
{
DynamoLogger?.Log("attempting reload of cpython3 modules", LogLevel.Console);
DynamoLogger?.Log("attempting reload of pythonnet3 modules", LogLevel.Console);
using (Py.GIL())
{
//the following is inspired by:
Expand Down Expand Up @@ -232,7 +257,7 @@
Analytics.TrackEvent(
Dynamo.Logging.Actions.Start,
Dynamo.Logging.Categories.PythonOperations,
"CPythonReset");
"PythonNet3Reset");
}
}

Expand Down
Loading