why does this hang

John Hunter jdhunter at nitace.bsd.uchicago.edu
Sun Aug 19 17:46:24 EDT 2001


>>>>> "Alex" == Alex Martelli <aleaxit at yahoo.com> writes:

    Alex> Yes, but not with Boost Python -- generally such weirdness
    Alex> results from wrong reference count handling in the extension
    Alex> (addref/decref not correctly matched) and Boost Python in my
    Alex> experience handles those for you smoothly and without
    Alex> errors.  Strange...

I found (I think) the source of the problem.  I was calling something
like

d = Date()
print 'the date is %s' % d

but had not defined __str__ to boost::python.  However, the C++ class
did overload operator<<().  Since I have provided __str__ to boost
python, I have had no problems....  Eg,

std::string 
py_Date_to_string( const Date& d )
{
  return d.get_sql_datetime();
}


Date::Date(boost::python::module_builder& m)
  : boost::python::class_builder<Date >(m, "Date")
{

 [snip]
  def(py_Date_to_string, "__str__");

}


Apparently boost::python attempts to call operator<<() when it needs a
string representation of the object if __str__ is not defined.
Perhaps the implementation of this is buggy, perhaps something else is
going on.

Regards,
John Hunter



More information about the Python-list mailing list