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


Groups > comp.lang.python > #111727

Re: Technique for safely reloading dynamically generated module

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Terry Reedy <tjreedy@udel.edu>
Newsgroups comp.lang.python
Subject Re: Technique for safely reloading dynamically generated module
Date Thu, 21 Jul 2016 13:32:36 -0400
Lines 24
Message-ID <mailman.36.1469122373.22221.python-list@python.org> (permalink)
References <1469112141.379402.672830825.05659985@webmail.messagingengine.com> <nmqqd2$lcd$1@ger.gmane.org> <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com> <nmr0vl$5e5$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de oiR7aMGJyj2pElnN4JI3lA21dEWvhRnP9AJo5mGiNb2g==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'classes,': 0.05; '__name__': 0.07; 'namespace': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'assume': 0.11; 'jan': 0.11; 'interpreter': 0.15; 'downside': 0.16; 'malcolm': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'true:': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'shell': 0.18; 'input': 0.18; 'exec': 0.22; 'references': 0.23; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'module.': 0.27; 'objects': 0.29; 'code': 0.30; 'run': 0.33; 'except': 0.34; 'next': 0.35; 'there': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'drop': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'received:96': 0.63; 'disappear': 0.84; 'disappears': 0.84; 'received:fios.verizon.net': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host pool-96-227-207-81.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <nmr0vl$5e5$1@ger.gmane.org>
X-Mailman-Original-References <1469112141.379402.672830825.05659985@webmail.messagingengine.com> <nmqqd2$lcd$1@ger.gmane.org> <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com>
Xref csiph.com comp.lang.python:111727

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web