From: Ype K. <yk...@xs...> - 2001-09-03 18:25:46
|
Silvio, >Hello everybody, >I'm preparing a presentation to show the work I did in Jython and CPython to the rest of my team (most of them don't know anything about Python), and explain them what we can do with this powerful "new stuff". >Among the other things, I should explain why in Jython we can import directly the Java packages while in CPython we have to deal with creating extension modules. >I am going to simplify things like this (please someone tell me if I'm wrong!): >Jython translates Python objects, exceptions and threads to real Java ones. So the logic for the run-time handling of objects (including memory allocation, for example), exceptions and threads is all in the JVM, the Jython interpreter behaves more or less like an interface. Correct, but it doesn't seem right to confuse an interpreter and an interface. You might say that the interpreter is implemented in the JVM, ie. it is "just another" java program. > This allows the seamless integration, since other programs of the Java platform are running over the same JVM. Yes. >CPython interpreter is coded in C, and relies directly on the OS. The logic for run-time handling of objects and exceptions, and for handling threads over the OS ones (that are more "stupid" than Python or Java ones) is coded inside the interpreter. However, Jython threads are much closer to Java threads and CPython threads are to C threads. (Python's thread model was designed to be similar to java's thread model.) > That's why extensions are needed, to make the C code deal with Python objects, exceptions and threads (exceptions and new object definitions are actually handled in a Python wrapper module, and not directly in the C extension, but anyway that's a logical part of the extension as well). I'd put it the other way around: from within jython you can call java code directly because of the introspection abilities of the java language. This introspection allows the mapping of Jython types to/from java types that is built into jython. When you want to call jython code from java code you still need to conform to jython implementation conventions (ie. import things from the org.python.core package). C does not have such detailed introspection, so C code that is available to the CPython interpreter must conform to the more rigid interface definitions of Python C extension modules, ie. C header files, to be called correctly. >Is it correct? Yes. >Did I catch the real reasons? Yes, but not all of them. Probably there are even more. Could someone else give a comparison between using org.python.core from java and using the Python wrapper module from C python extensions? I have no experience in the latter. >thanks for your help, >Silvio. My pleasure, Ype > >_______________________________________________ >Jython-users mailing list >Jyt...@li... >https://lists.sourceforge.net/lists/listinfo/jython-users |