you’re entering a minefield there…
Since you’ve built your flowgraph using GRC, you have a
python-constructed flowgraph. That’s why things start to get confusing
for the c++ developer.
First of all, destructors of python objects are called whenever the
python runtime feels like it - this often happens when you do something
like
object_name = None
but it doesn’t necessarily has to happen right away. The Garbage
Collector can choose when to do it, and sometimes, it decides not to do
it at all - if your program terminates first, this might be the case.
Furthermore, if it decides that at the end of runtime, it should
destruct its output stream file handles before destructing your block,
your printf output might be lost.
Then: You have a C++ object wrapped by SWIG. So, what you’re seeing in
Python is not actually an instance of your block, it is a SWIG object
holding a reference to such an instance. Usually, when that Swig
Object’s python destructor is called, it should delete the block
instance, too, but then again, if I knew what really happens inside
SWIG, I’d feel a lot wiser.
Lastly: Destructors doing actual work is a tricky thing. Mostly,
because, what does the runtime (both, c++ or python) do when a
destructor throws an exception? In that case, should the runtime ignore
it and just think “meh, whatever, it’s dead anyway” or should it cause
the program to exit with a failure state? And: what if a C++ destructor
fails that got called by the python garbage collector? That shouldn’t
crash the global python interpreter, should it?
So these are the pitfalls I could think of. Maybe the situation is a lot
easier, though Post some code, maybe a github gist or a pastebin!
First of all, destructors of python objects are called whenever the python
runtime feels like it - this often happens when you do something like object_name
= None but it doesn’t necessarily has to happen right away.
The Garbage Collector can choose when to do it, and sometimes, it decides not to
do it at all - if your program terminates first, this might be the case.
Furthermore, if it decides that at the end of runtime, it should destruct its
output stream file handles before destructing your block, your printf output might
be lost.
So I know it isn’t just dropping printf output, as other “clean-up” code
does not execute.
So these are the pitfalls I could think of. Maybe the situation is a lot easier,
though Post some code, maybe a github gist or a pastebin!
All excellent ideas, especially the GC that rightfully turns up its
nose at any destructor complaints.
So it is good to know that it is a bit out of my hands, but I can
certainly move my “clean-up” code to the point where the work() method
signals WORK_DONE. Sorry, I can’t possibly air my dirty laundry on a
pastebin :(.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.