Boost logo

Boost Users :

From: dima_mouromtsev (dima_mouromtsev_at_[hidden])
Date: 2003-05-14 08:00:58


Hello All!

I've the problem with the next code:

class MyWindow
{
  ...
  MyWindow() {}
  ~MyWindow() {}

  MyOperation()
  {
    Py_Initialize();

    handle<> main_module(borrowed(PyImport_AddModule("__main__")));
    handle<> namespace(borrowed(PyModule_GetDict(main_module.get())));
    try {
      handle<>(PyRun_String("hello = file('c:\\hello.txt', 'w')\n"
                        "hello.write('Hello world!')\n"
                        "hello.close()", Py_file_input,
                        namespace.get(), namespace.get()));
    } catch(error_already_set) {
      ...
    }

    Py_Finalize();
  }
};

When I start this code, that's all right.

If I move Py_Finalize() to destructor, the program work, but when I
close the program an exeption rise (Py_FatalError("UNREF invalid
object")).

Next, I exclude Boost classes:

...
  MyOperation()
  {
    PyObject* dict = PyModule_GetDict(PyImport_AddModule("__main__"));
    PyRun_String("hello = file('c:\\hello.txt', 'w')\n"
                 "hello.write('Hello world!')\n"
                 "hello.close()", Py_file_input, dict, dict);
  }

So the program work well and there is no exeptions at exit.

What is my problem? How can I use Boost in right way?

Please Help
Thanks
Dima


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net