Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111727 > unrolled thread

Re: Technique for safely reloading dynamically generated module

Started byTerry Reedy <tjreedy@udel.edu>
First post2016-07-21 13:32 -0400
Last post2016-07-21 13:32 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Technique for safely reloading dynamically generated module Terry Reedy <tjreedy@udel.edu> - 2016-07-21 13:32 -0400

#111727 — Re: Technique for safely reloading dynamically generated module

FromTerry Reedy <tjreedy@udel.edu>
Date2016-07-21 13:32 -0400
SubjectRe: Technique for safely reloading dynamically generated module
Message-ID<mailman.36.1469122373.22221.python-list@python.org>
On 7/21/2016 12:07 PM, Malcolm Greene wrote:

> I assume that one downside to the exec() approach is that there is no
> persistent namespace for this code's functions and classes, eg. after
> the exec() completes, its namespace disappears and is not available to
> code that follows?

Objects only disappear when no references are left.  So it is up to you 
whether you drop the namespace and use a new one for the next exec call 
or whether you use the same namespace over and over.  IDLE's run module 
does the latter.  Simplified, IDLE's Shell simulates the interactive 
interpreter by sending user input to this code in the run module.

main = fake_main()  # with __name__ = '__main__', __builtins__ = ...
while True:
     try:
         code = user_input()
         exec(code, main)
     except BaseException as e:
         handle_exception(e)

-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web