[IPython-user] embedding IPython in windows dll
mani sabri
mani.sabri@gmail....
Sun Mar 9 17:42:55 CDT 2008
Hello
I'm using:
- Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
- IPython 0.8.2
Short story: Can't launch an Ipython shell from a dll with the bellow code.
Long story: There is an online trading program (Metatrader) and I'm trying
to open an Ipython shell for it. Because it's not an opensource project I
came up with the solution of opening the shell in the dllmain() of a dll
that is importable in the scripting environment of its expert advisors[1].
The dll is attached to the program as long as the expert is working so it
can somehow hold the shell and other stuff! BTW I came up with these:
PyObject *dt=NULL,*b=NULL,*modstring=NULL,*mod=NULL;
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID
lpReserved)
{
//----
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
if (!Py_IsInitialized())
{
Py_Initialize();
if (!Py_IsInitialized()) return(FALSE);
import_array1(-1);
modstring = PyString_FromString("numpy");
mod = PyImport_Import(modstring);
PyRun_SimpleString("dt = numpy.dtype([('ctm', uint),
('open', double), ('low', double), ('high', double), ('close', double),
('vol', double)])");
PyRun_SimpleString("from IPython.Shell import
IPShellEmbed");
PyRun_SimpleString("ipshell = IPShellEmbed()");
PyRun_SimpleString("ipshell()");
}
break;
}
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
{
Py_XDECREF(mod);
Py_XDECREF(modstring);
Py_XDECREF(dt);
Py_XDECREF(b);
Py_Finalize();
break;
}
}
Dll doesn't crash or ... everything works fine but there is no shell! Can
anybody help?
Pls Don't laugh at the fabulous API usage ;-) its too complicated and I'm
still learning.
Best regards,
Mani
[1] scripts that are triggered at market changes. (I think I have to run
Ipython in a separate thread. Am I right?)
P.S That was my first email in this list! Thank you for the great job...
More information about the IPython-user
mailing list