Monkey patch an entire file in a python package

2015-03-24 Thread enjoyaol
This question is about python 2.7 on Windows 7

I am trying to use multiprocessing with freeze. It appears there is some bug 
when using multiprocessing on freezed python code on windows platforms. There 
is this patch which made its way to python 3.2, and works in 2.7:

http://bugs.python.org/file20603/issue10845_mitigation.diff

I would like to monkey patch it.

Problem is, this patch is for "forking.py", used by multiprocessing.Pools 
Multiprocessing is using forking.py to launch processes. I would like to monkey 
patch this way :

import multiprocessing
import multiprocessing_fixed
multiprocessing_fixed:

import multiprocessing.forking as mpf
def prepare(data):
[include fixed code for this method]
mpf.prepare = prepare_pyz
It's not working because forking.py is launched like a python module.

How to solve this problem ?

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


Re: Monkey patch an entire file in a python package

2015-03-24 Thread enjoyaol
Le mardi 24 mars 2015 13:11:33 UTC+1, Chris Angelico a écrit :
> On Tue, Mar 24, 2015 at 10:50 PM,   wrote:
> > I am trying to use multiprocessing with freeze. It appears there is some 
> > bug when using multiprocessing on freezed python code on windows platforms. 
> > There is this patch which made its way to python 3.2, and works in 2.7:
> >
> > http://bugs.python.org/file20603/issue10845_mitigation.diff
> >
> > I would like to monkey patch it.
> 
> Do you have to monkey-patch at run-time? It might be better to simply
> patch your Python installation once, and then have the change deployed
> globally. Given that it was applied to 3.2, I doubt it's going to
> break much, so you can probably afford to just edit the file and have
> done with it.
> 
> Alternatively, you may be able to put your own forking.py earlier in
> PYTHONPATH, and thus shadow the stdlib module. That might require you
> to shadow all of multiprocessing, though.
> 
> ChrisA

Unfortunately, I would need to do it at runtime.
I will look into the PYTHONPATH idea, thanks
-- 
https://mail.python.org/mailman/listinfo/python-list