473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

several interpreters and suspend script

Hello All,

I'm working ( and a beginner ) with mixing Python scripting and C++.

And I need some little help. :)
I've searched on the net, but found no answer. So I ask you directly.

Globally, I'd like to do 2 things.

The first, when I'm in the program, I call a script, which call a function
to open a window.
And when the window is opened the script should stop / wait, until the
window closes, and then continue.
Does any function exists to do this ?

#---------------------------------------------------------------------------------------------------------------------
import MyModule

def ok_cb():
global w
MyModule.Warning_All( "closing window" )
w.Close() #after here, the script should continue

#create the window
w = MyModule.cPythonWindow( "win", U"win", 0 )

#add some buttons, and when we push one, the function ok_cb is called
w.AddActionButton( "ok", "OK", ok_cb )
w.AddIntegerButton( "int", "Nb", 2541, ok_cb )

#open the window
w.Open() #we should stay here until the callback ends (when we push a
button) and the window close

#it should show this message when the window closes and not directly
after the window is created
MyModule.Warning_All( "exiting script" )
#---------------------------------------------------------------------------------------------------------------------

The second problem ( which is in relation with the first ) is when we have 2
non-modal windows, at the same time.
If the 2 scripts stops/are suspended, all the variables in the scripts must
be totally independent.
So, I'd like that the 2 "spaces" of these scripts are independent.
I wanted to use the Py_NewInterpreter() but it failed in
PyThreadState_Swap() with this error : "PyFatalError("Invalid thread state
for this thread");".
So I use 2 dictionaries for each script, but is it sufficient?
What about the call stack ? Where/how is it saved ?

//---------------------------------------------------------------------------------------------------------------------
class cPython
{
public:
virtual ~cPython();
cPython();
public:
int Run( const char* iArgs );

void Module( const char* iModuleName, PyMethodDef* iModuleMethod );
void Dictionary( const char* iModuleName );

private:
PyObject* mMainModule;
PyObject* mGlobalDictionary;
PyObject* mLocalDictionary;
};
void
cPython::Module( const char* iModuleName, PyMethodDef* iModuleMethod )
{
mMainModule = Py_InitModule( iModuleName, iModuleMethod );
PyDict_Merge( PyModule_GetDict( mMainModule ), PyModule_GetDict(
PyImport_AddModule( "__main__" ) ), true );
}
void
cPython::Dictionary( const char* iModuleName )
{
mGlobalDictionary = PyDict_Copy( PyModule_GetDict( mMainModule ) );
PyDict_SetItemString( mGlobalDictionary, iModuleName, mMainModule );

mLocalDictionary = PyDict_Copy( PyModule_GetDict( mMainModule ) );
}
int
cPython::Run( const char* iArgs )
{
PyObject* run_string = PyRun_String( iArgs, Py_file_input,
mGlobalDictionary, mLocalDictionary );
Py_XDECREF( run_string );
return 0;
}
cPython pyt;
pyt.Module( L"MyModule", sgMethods ); //create the module "MyModule"
InitPythonProject( pyt.Module() ); //add the "class" project in the
module "MyModule"
InitPythonLayer( pyt.Module() ); //add the "class" layer in the module
"MyModule"
InitPythonWindow( pyt.Module() ); //add the "class" window in the
module "MyModule"
pyt.Dictionary( L"MyModule ); //create the 2 dictionary

pyt.Run( L"MyPath/MyFile.py" );
//---------------------------------------------------------------------------------------------------------------------

If I create more python objects, the dictionaries are different but not the
module( there is no copy of the module for the next python object ), right?
And can this make problems for globals variables or callstack for each
suspended script ?

Here, that's all :)

So, if you have any suggestions ( or even solutions ).

Thanks for reading

Regards
Oct 24 '05 #1
0 1353

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Johan Fredrik Ohman | last post by:
Hi, I'd like to use the newest interpreter if available. I tried a little bash scripting, but with no success. Is there some easy way to check a list of possible interpreters and path, and when...
4
by: Paul Miller | last post by:
Some background first - we have some software that embeds a Python interpreter into a host application. Scripts are loaded dynamically and used. But we want to support the ability to edit scripts...
4
by: Steve | last post by:
Hi, How can I send a python script a suspend signal? I need to suspend a script that frequently updates the database so that I can do a "vacuum" on the database without affecting the script....
2
by: bmatt | last post by:
I am trying to support multiple interpreter instances within a single main application thread. The reason I would like separate interpreters is because objects in my system can be extended with...
1
by: Craig Ringer | last post by:
Hi folks I'm a bit of a newbie here, though I've tried to appropriately research this issue before posting. I've found a lot of questions, a few answers that don't really answer quite what I'm...
11
by: Keith Langer | last post by:
I have an application which consists of a main work thread and multiple threads which each maintain a TCP socket. When a configuration change occurs, all activity on the socket threads must be...
2
by: Sakharam Phapale | last post by:
Hi All, In following example, while playing file, if thread goes in WaitSleepJoin state, due to Thread.Sleep method. Now I want to suspend thread by clicking on cmdSuspend button. I have...
0
by: vishnu | last post by:
Hello All, I have embedded python 2.5 in to my C application. As we need the python scripts to run in multi threaded environment I have used Py_NewInterpreter() and Py_EndInterpreter each time I...
0
by: michael.spoden | last post by:
Hi, I'm working with DB2 UDB V8.2 Fixpak 14 on Linux. Since two days the 'set write suspend on database' command takes multiple hours in our backup script in the night. Theres more or less no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.