I want to make an existing CLI application more user friendly with wxPython FileDialog. But on several machines running Windows 7, the console is slowly filled with blank lines (say: one line every minute - didn’t measure precisely) after a FileDialog has been created.
Below is a small piece of code that triggers the problem:
import msvcrt
import wx
if __name__ == '__main__':
print("Starting...")
app = wx.App()
openFileDialog = wx.FileDialog(None, message="Open a .tiff image", defaultFile="", wildcard="Tiff images (*.tiff)|*.tiff", style=wx.FD_OPEN | wx.DIALOG_NO_PARENT)
# after the call to ShowModal, extra lines in the console output appear every x seconds.
# Destroying the dialog or App does not solve the problem
print("Showing openFileDialog...")
openFileDialog.ShowModal()
print("Destroying openFileDialog...")
openFileDialog.Destroy()
openFileDialog = None
app.Destroy()
app = None
msvcrt.getch()
print("Exiting...")
The problem still occurs with input(). And I’ve seen originally the problem in an application using Matplotlib to show some plots interactively.
I assume that destroying the FileDialog and App releases all wxPython resources. Yet, the blank lines still appear. So creating the FileDialog might just act as a trigger.
Another observation: when capturing stdout via the file descriptor and checking the output, the blank lines all appear at the beginning, followed by the regular sys.stdout output. So this looks like the offending code doesn’t use Python I/O, but directly accesses the file descriptor (the problem might be in a C library).
Script used for this test (and I’ve waited some time before pressing enter to quit):
import wx
import time
if __name__ == '__main__':
print("Starting...")
app = wx.App()
openFileDialog = wx.FileDialog(None, message="Open a .tiff image", defaultFile="", wildcard="Tiff images (*.tiff)|*.tiff", style=wx.FD_OPEN | wx.DIALOG_NO_PARENT)
# after the call to ShowModal, extra lines in the console output appear every x seconds.
# Destroying the dialog does not solve the problem
print("Showing openFileDialog...")
openFileDialog.ShowModal()
print("Destroying openFileDialog...")
openFileDialog.Destroy()
openFileDialog = None
app.Destroy()
app = None
print("Sleeping...")
time.sleep(120)
print("Waiting for <enter>...")
input()
print("Exiting...")
and the output
Starting...
Showing openFileDialog...
Destroying openFileDialog...
Sleeping...
Waiting for <enter>...
Exiting...
I’m still unable to replicate this. I tried with multiple Windows VMs and versions of wxPython.
Do you have something else installed on the system that may have hooked into the Windows message queues that might be trying to monitor or interact with all running applications in some way? Since your application is not responding to Windows messages at that point in time (neither the MainLoop nor ShowModal are running) then perhaps some other thing is trying to prod or wake up your app by writing to its stdio pipes…
One step further. Indeed, it is another application that causes the problem. This occurs on some corporate machines with several tools preinstalled. I’ve disabled the Windows service for “Druva inSync”, a tool for on-line backup, and the problem is gone.
ApiMon revealed some calls to WriteFile from “insyncce.dll”, a DLL that is injected in Python. At this point I’m not sure if it is wxPython specifically that triggers this issue, or more in general the Windows FileDialog. But it is a bug in Druva anyway.
The problem is not caused by wxPython, 100% sure now. Sorry for wasting your time.
I’ve created a similar version with PyQt. When using the native file dialog, the problem occurs there too. When using a non-native file dialog, the problem does not occur.
So everything is pointing to Druva inSync trying to inject itself in applications using the Windows file dialog, and accidentally causing extra output on stdout.