embedding: how to create an "idle" handler to allow user to kill scripts?

D

David M. Cotter

in my C++ app, on the main thread i init python, init threads, then call PyEval_SaveThread(), since i'm not going to do any more python on the main thread.

then when the user invokes a script, i launch a preemptive thread (boost::threads), and from there, i have this:

static int CB_S_Idle(void *in_thiz) {
CT_RunScript *thiz((CT_RunScript *)in_thiz);

return thiz->Idle();
}

int Idle()
{
int resultI = 0;
OSStatus err = noErr;

ERR(i_taskRecP->MT_UpdateData(&i_progData));

if (err) {
resultI = -1;
}

ERR(ScheduleIdleCall());
return err;
}

int ScheduleIdleCall()
{
int resultI(Py_AddPendingCall(CB_S_Idle, this));
CFAbsoluteTime timeT(CFAbsoluteTimeGetCurrent());
SuperString str; str.Set(timeT, SS_Time_LOG);

Logf("$$$ Python idle: (%d) %s\n", resultI, str.utf8Z());
return resultI;
}

virtual OSStatus operator()(OSStatus err) {
ScPyGILState sc;

ERR(ScheduleIdleCall());
ERR(PyRun_SimpleString(i_script.utf8Z()));
return err;
}

so, my operator() gets called, and i try to schedule an Idle call, which succeeds, then i run my script. however, the CB_S_Idle() never gets called?

the MT_UpdateData() function returns an error if the user had canceled the script

must i schedule a run-loop on the main thread or something to get it to be called?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,037
Messages
2,570,371
Members
47,013
Latest member
JewellChes

Latest Threads

Top