'Where do I look to trace application exit call?
I have a VB.NET WinForms application which calls a video display subsystem written in Native C++. (DirectShow)
After a number of sessions rendering several video files, the application simply exits, without any indicators as to why.
There is no exception, unhandled or otherwise.
As best I can determine from log file records, the application exits when it should be at an idle state, waiting for the next window action (button click) on the form.
There is a Forms_Closing event handler, but it never seems to be called.
The problem is intermittent, and rare. I suspect some kind of memory corruption in the C++ Native code might be the cause.
How can I hook the method which is calling the "Application.Exit" processing?
Is there some other way to determine where the call originates which shuts down the application?
Solution 1:[1]
Based on this answer to 'Iterating through globals() dictionary', you can typecast your globals().values() to a list so that you can iterate on it without the error RuntimeError: dictionary changed size during iteration, which is presently what your code with for f in globals().values(): gives. Here's that change incorporated:
# Get a list of all user-defined functions and print their definitions
import inspect, sys, types
# sys.stdout.write(inspect.getsource(MyFunction))
#
print(sorted([f.__name__ for f in globals().values() if type(f) == types.FunctionType]))
print()
for f in list(globals().values()):
if type(f) == types.FunctionType:
## %pdef $f.__name__ is only the call signature
print(inspect.getsource(f))
The solution was found by running your code and seeing the error and then searching about errors iterating on globals. So in the future, it is suggested when posting to provide the error you see and what you expect as @juanpa.arrivillaga suggested. Also, please provide any steps you've already tried to fix it. In this case, you may have sorted it yourself by following that process as it was a direct substitution suggested. Granted, when learning it is often harder to understand what to search and how to effectively sort and implement those findings.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
