How make your module substitute a python stdlib module.

Antoon Pardon antoon.pardon at vub.be
Tue Dec 27 08:25:00 EST 2022



Op 27/12/2022 om 13:46 schreef Chris Angelico:
> On Tue, 27 Dec 2022 at 23:28, Antoon Pardon<antoon.pardon at vub.be>  wrote:
>> At the moment I am happy with a solution that once the programmer has
>> imported from QYZlib.threaders that module will used as the threading
>> module.
>>
> Oh! If that's all you need, then yes, a simple patch of sys.modules
> will work. You'll have to make sure you get your module imported
> before anything else pulls up the vanilla one, though. Otherwise, your
> only option is to keep the existing module object and monkeypatch it
> with whatever changes you need.
>
> But a simple "sys.modules['threading'] = QYZlib.threaders" will work.
> Of course, how *well* this works depends also on how well that module
> manages to masquerade as the threading module, but I'm sure you've
> figured that part out :)

Well it is what will work for the moment. Thanks for the confirmation
this will indeed work.

-- 
Antoon Pardon.


More information about the Python-list mailing list