Issue 4612: PyModule_Create() doesn't add/import module (original) (raw)

Created on 2008-12-09 15:41 by blakemadden, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg77428 - (view) Author: blake madden (blakemadden) Date: 2008-12-09 15:41
In reference to Issue4592 (which includes a patch), PyModule_Create()calls PyModule_New instead of PyImport_AddModule. Because of this, calling PyModule_Create() won't work like Py_InitModule(). Is this correct, because the documentation is showing that PyModule_Create() is all you need to use to create and add a module to the system. However, this is not the case.
msg77439 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-12-09 18:35
Are you returning the module in your extension's init function? The import machinery takes the returned module from the init function and adds it to sys.modules for you.
msg77442 - (view) Author: blake madden (blakemadden) Date: 2008-12-09 19:35
Sorry, mate, that's all Greek to me--I'm a total noob with Python. I'm simply trying to run the example in r67655 (the "Extending Embedded Python" example) and it fails with "'emb' not being found". It appears that calling "PyModule_Create(&EmbModule);" is not enough to create and import the library. Somebody made a comment in Issue4592 that "PyModule_Create" was missing some logic, so I'm reporting that here. I honestly don't know if there is something wrong with "PyModule_Create" or if the example is missing something. I'm just trying to get this example to work.
msg77447 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-12-09 20:56
Ah, I had not looked at the issue; sorry about the confusion. PyImport_Create() is doing what it is supposed to be doing and should not call PyImport_AddModule(). The example is wrong. Closing this as invalid since the example is off.
msg77465 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-12-09 22:34
When python is embedded in a program, there must be a way for the program to export some of its functions to python - a module that resides in the main executable. You cannot use the import machinery to import such a module, because there is no separate file to find and load. Instead, the embedding program explicitly calls the module init() function. With python 2.x, this creates the module *and* inserts it into sys.modules. Then subsequent imports will find it directly in sys.modules. mod_python for example works this way. I maintain that the sample is still valid, and should be made to work somehow.
msg77467 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-12-09 22:36
On Tue, Dec 9, 2008 at 14:34, Amaury Forgeot d'Arc <report@bugs.python.org> wrote: > > Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment: > > When python is embedded in a program, there must be a way for the > program to export > some of its functions to python - a module that resides in the main > executable. > > You cannot use the import machinery to import such a module, because > there is no > separate file to find and load. Instead, the embedding program > explicitly calls the > module init() function. > With python 2.x, this creates the module *and* inserts it into > sys.modules. Then > subsequent imports will find it directly in sys.modules. > > mod_python for example works this way. > I maintain that the sample is still valid, and should be made to work > somehow. That's what I mean; the example is off as in incorrect. Not off as in trying to do something silly.
msg77468 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-12-09 22:44
OK. I'm currently writing a documentation patch for .
History
Date User Action Args
2022-04-11 14:56:42 admin set github: 48862
2008-12-09 22:44:15 amaury.forgeotdarc set messages: +
2008-12-09 22:36:33 brett.cannon set messages: +
2008-12-09 22:34:19 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2008-12-09 20:56:20 brett.cannon set status: pending -> closedresolution: not a bugmessages: +
2008-12-09 19:35:58 blakemadden set messages: +
2008-12-09 18:35:32 brett.cannon set status: open -> pending
2008-12-09 18:35:05 brett.cannon set nosy: + brett.cannonmessages: +
2008-12-09 15:41:10 blakemadden create