Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51400

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

Newsgroups comp.lang.python
Date 2013-07-28 12:21 -0700
Message-ID <55e03ef8-d1db-4ae0-88a5-7641fb4b1b57@googlegroups.com> (permalink)
Subject embedding: how to create an "idle" handler to allow user to kill scripts?
From "David M. Cotter" <me@davecotter.com>

Show all headers | View raw


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?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

embedding: how to create an "idle" handler to allow user to kill scripts? "David M. Cotter" <me@davecotter.com> - 2013-07-28 12:21 -0700
  Re: embedding: how to create an "idle" handler to allow user to kill scripts? "David M. Cotter" <me@davecotter.com> - 2013-07-30 12:56 -0700

csiph-web