Reason for not allowing import twice but allowing reload()

Steven D'Aprano steve at pearwood.info
Tue Mar 1 12:11:17 EST 2016


On Tue, 1 Mar 2016 10:39 pm, Chris Angelico wrote:

> On Tue, Mar 1, 2016 at 10:18 PM, Steven D'Aprano <steve at pearwood.info>
> wrote:
>> I cannot imagine why you would want to reload() in production code. That
>> would imply that your production code is modifying already-imported
>> modules, then wanting to import them again. Why would anyone in their
>> right mind do that? Possibly because they lost a bet?
> 
> BartC and I have both done this exact thing, though neither of us used
> Python for it. It's not so insane as you might think; sometimes you
> want to update code, but you don't want to restart a process. Just
> because you've never had a process that hits a year of uptime doesn't
> mean nobody else does. :)

I've had an uptime of over 400 days on my laptop, without logging out, so
yes I have had processes with over a year of uptime. But that doesn't mean
I expect to modify the code of a running process and reload it. Modify
data, sure, but not code.

I'll grudgingly accept that, just maybe, if you have some sort of plugin
system, you may want to unload and reload plugins, replacing the old plugin
with a new one of the same name. Maybe you could get that to work in Python
using the import system.


-- 
Steven




More information about the Python-list mailing list