c++ - Starting threads within Python extensions -


i'm trying start thread within swig python c++ extension, however, when go run it produces following:

libc++abi.dylib: terminating abort trap: 6 

i'm guessing there shouldn't issue gil since no python-allocated objects being used. or wrong in assumption?

a minimal example:

// _myextension.cpp #include <iostream> #include <thread> void threadfunc() {     std::cout << "thread started" << std::endl;     std::this_thread::sleep_for (std::chrono::seconds(10));     std::cout << "thread ended" << std::endl; } void start() {     std::thread first (threadfunc); }   // _myextension.i %module _myextension %{ extern void start(); %} extern void start();   // test.py import _pymapper _pymapper.start() 

simple fix, thread has detached after being created, so:

void start() {     std::thread first (threadfunc);     first.detach(); } 

then, works fine! however, thread killed prematurely once statements have been completed in original python script. fixed adding function call extension rejoins thread.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -