8000 Flush the console on every WriteLine so messages are in order. · pythonnet/pythonnet@dd77fa5 · GitHub
[go: up one dir, main page]

Skip to content

Commit dd77fa5

Browse files
author
Benoit Hudson
committed
Flush the console on every WriteLine so messages are in order.
The sub-domain writelines were coming all at once, not interwoven as expected. This seems to be the cause of an occasional TCP transport error on travis (we're writing to a closed pipe).
1 parent 8a80fd5 commit dd77fa5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/embed_tests/TestDomainReload.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public static void RunPython() {
8383
AppDomain.CurrentDomain.DomainUnload += OnDomainUnload;
8484
string name = AppDomain.CurrentDomain.FriendlyName;
8585
Console.WriteLine(string.Format(""[{0} in .NET] In PythonRunner.RunPython"", name));
86+
Console.Out.Flush();
87+
8688
using (Py.GIL()) {
8789
try {
8890
var pyScript = string.Format(""import clr\n""
@@ -96,11 +98,13 @@ public static void RunPython() {
9698
PythonEngine.Exec(pyScript);
9799
} catch(Exception e) {
98100
Console.WriteLine(string.Format(""[{0} in .NET] Caught exception: {1}"", name, e));
101+
Console.Out.Flush();
99102
}
100103
}
101104
}
102105
static void OnDomainUnload(object sender, EventArgs e) {
103-
System.Console.WriteLine(string.Format(""[{0} in .NET] unloading"", AppDomain.CurrentDomain.FriendlyName));
106+
Console.WriteLine(string.Format(""[{0} in .NET] unloading"", AppDomain.CurrentDomain.FriendlyName));
107+
Console.Out.Flush();
104108
}
105109
}";
106110

@@ -156,13 +160,15 @@ public void InitAssembly(string assemblyPath)
156160
public void RunPython()
157161
{
158162
Console.WriteLine("[Proxy] Entering RunPython");
163+
Console.Out.Flush();
159164

160165
// Call into the new assembly. Will execute Python code
161166
var pythonrunner = theAssembly.GetType("PythonRunner");
162167
var runPythonMethod = pythonrunner.GetMethod("RunPython");
163168
runPythonMethod.Invoke(null, new object[] { });
164169

165170
Console.WriteLine("[Proxy] Leaving RunPython");
171+
Console.Out.Flush();
166172
}
167173
}
168174

@@ -173,6 +179,7 @@ public void RunPython()
173179
static void RunAssemblyAndUnload(Assembly assembly, string assemblyName)
174180
{
175181
Console.WriteLine($"[Program.Main] === creating domain for assembly {assembly.FullName}");
182+
Console.Out.Flush();
176183

177184
// Create the domain. Make sure to set PrivateBinPath to a relative
178185
// path from the CWD (namely, 'bin').
@@ -203,17 +210,21 @@ static void RunAssemblyAndUnload(Assembly assembly, string assemblyName)
203210
theProxy.RunPython();
204211

205212
Console.WriteLine($"[Program.Main] Before Domain Unload on {assembly.FullName}");
213+
Console.Out.Flush();
206214
AppDomain.Unload(domain);
207215
Console.WriteLine($"[Program.Main] After Domain Unload on {assembly.FullName}");
216+
Console.Out.Flush();
208217

209218
// Validate that the assembly does not exist anymore
210219
try
211220
{
212221
Console.WriteLine($"[Program.Main] The Proxy object is valid ({theProxy}). Unexpected domain unload behavior");
222+
Console.Out.Flush();
213223
}
214224
catch (Exception)
215225
{
216226
Console.WriteLine("[Program.Main] The Proxy object is not valid anymore, domain unload complete.");
227+
Console.Out.Flush();
217228
}
218229
}
219230

0 commit comments

Comments
 (0)
0