You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Module function is doing push_back one-array by input integer.
It defines this module when importing, explicitly delete it, and then import it as another module.
I expect each module has 1 array, but inner array is kept and grows.
Occurs in the following codes....
[C++(main.cpp)]
#include <pybind11/pybind11.h>
std::vector _array(0);
int CreateArray(int a)
{
_array.push_back(a);
return _array.size();
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This may be similar to #4014
Module function is doing push_back one-array by input integer.
It defines this module when importing, explicitly delete it, and then import it as another module.
I expect each module has 1 array, but inner array is kept and grows.
Occurs in the following codes....
[C++(main.cpp)]
#include <pybind11/pybind11.h>
std::vector _array(0);
int CreateArray(int a)
{
_array.push_back(a);
return _array.size();
}
PYBIND11_MODULE(arrayproc, m) {
m.doc() = "pybind11 example";
m.def("CreateArray", &CreateArray, "");
}
[Compile]
g++ -O3 -Wall -shared -std=c++11 -fPIC
python3 -m pybind11 --includes
main.cpp -o arrayprocpython3-config --extension-suffix
[Python(main.py)]
if name == 'main':
import arrayproc as test1
list1 = test1.CreateArray(5)
del(test1)
import arrayproc as test2
list2 = test2.CreateArray(5)
del(test2)
import arrayproc as test3
list3 = test3.CreateArray(5)
[Result]
Arraylength[list1]= 1
Arraylength[list2]= 2
Arraylength[list3]= 3
How can I avoid this?
Best Regards,
Beta Was this translation helpful? Give feedback.
All reactions