Re: Load python from different plugin dlls

2020-02-13 Thread Eko palypse
Thanks for the information.
My test looks like this right now.
I have two plugins which, when loaded separately, work.
But when both are loaded, I get AccessVioletion messages from python37.dll.
The init code for both dlls is this:

cpp_init_code = f'''#include 
#include "PluginInterface.h"

PyMODINIT_FUNC PyInit_{PLUGIN_NAME}(void);

BOOL APIENTRY DllMain( HANDLE hModule,
   DWORD reasonForCall,
   LPVOID /* lpReserved */ )
{{
switch ( reasonForCall )
{{
case DLL_PROCESS_ATTACH:
PyImport_AppendInittab("{PLUGIN_NAME}", &PyInit_{PLUGIN_NAME});
Py_InitializeEx(Py_IsInitialized() ? 0 : 1);
PyImport_ImportModule("{PLUGIN_NAME}");
break;
case DLL_PROCESS_DETACH:
Py_Finalize();
break;

case DLL_THREAD_ATTACH:
break;

case DLL_THREAD_DETACH:
break;
}}

return TRUE;
}}'''

This is written to a plugininit.cpp file and then built via setup.py with
distutil, cython and VS2017.

According to the docs  PyImport_AppendInittab should be called before
Py_Initialize
but I can't call  Py_Initialize the second time as it would remove what was
initialized by the first dll.
And using PyImport_ImportModule on the second dll only does not work either.
So that is were I'm trapped.

Thank you
Eren

Am Do., 13. Feb. 2020 um 07:26 Uhr schrieb R.Wieser :

> Eko,
>
> > which needs also access to python3.dll but cannot load it itself as it
> has
> > been already loaded by plugin1
> >
> > Is such a scenario actually possible?
>
> Yes.
>
> Normally a DLL can be loaded in as many processes (and threads thereof) as
> you like.
>
> However, it is possible that the DLLs initialisation contains code to
> check
> if something it needs is available*, and if not directly exit.
>
> *like if it can access certain I/O - if the first DLL instance "takes
> posession" the second DLL instance wil fail.  Than again, this can also
> happen when using two totally different plugin DLLs.
>
> tl;dr:
> Yes, but not likely.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Load python from different plugin dlls

2020-02-13 Thread R.Wieser
Eko,

> My test looks like this right now.

And there you have a probem, as I have no experience with what those 
functions do.   The below is therefore just a bit of educated guessing, so 
caveat emperor.

> According to the docs  PyImport_AppendInittab should be called
> before Py_Initialize

And should probably be done only once - adding the same module to the same 
list will likely fail, though the above function will than just return a -1 
(minus one) result.

>Py_InitializeEx(Py_IsInitialized() ? 0 : 1);

Initializing when already being initialized might well be the cause of your 
AccessViolation - the first plugin looses its objects, but still tries to 
use them.

Suggestion: Do a Py_IsInitialized() and if so skip the the Py_InitializeEx() 
(and maybe change that one to the simpler Py_Initialize() ).

Hope that helps.

Regards,
Rudy Wieser


-- 
https://mail.python.org/mailman/listinfo/python-list


first time python learner

2020-02-13 Thread Marty Konopko
Win 10
Anti Virus  off
[image: image.png]

Any idea?

-- 
Martin Konopko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: first time python learner

2020-02-13 Thread Cameron Simpson

On 13Feb2020 21:38, Marty Konopko  wrote:

Win 10
Anti Virus  off
[image: image.png]

Any idea?


Alas, this is a text only list; your screenshot has been discarded.  
Please reply with your complete error message cut/paste into the text.  
And a description of what you were trying to do.


Thanks,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: ghostscripts in python with watchdog

2020-02-13 Thread Bheesham Persaud

Hey!

If you change the "-sOutputFile` parameter you pass into gswin64c.

For example, something like:

output_directory = os.path.join(os.path.dirname(input_src), "out")

And then you should be able to modify the call to `os.system` to 
something like:


os.system(
"gswin64c -q -dBATCH -dNOPAUSE"
"-sOutputFile={output_directory}/page{page:04d}.pdf"
" -dFirstPage={page} -dLastPage={page}"
" -sDEVICE=pdfwrite {input_pdf}"
.format(
page=i,
input_pdf=input_pdf,
output_directory=output_directory
)
)
--
https://mail.python.org/mailman/listinfo/python-list