Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Malcolm Greene Newsgroups: comp.lang.python Subject: Re: Technique for safely reloading dynamically generated module Date: Thu, 21 Jul 2016 12:07:45 -0400 Lines: 19 Message-ID: References: <1469112141.379402.672830825.05659985@webmail.messagingengine.com> <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de vqAzwQzTXLnqXgRKy/liOw3QGn+LtsTaXFb5DeZfqw0Q== Return-Path: 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; 'context': 0.05; 'definitions': 0.07; 'namespace': 0.09; 'received:internal': 0.09; 'statements': 0.09; 'subject:module': 0.09; 'python': 0.10; 'assume': 0.11; 'downside': 0.16; 'from:addr:python': 0.16; 'malcolm': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'module?': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'exec': 0.22; 'defined': 0.23; 'references': 0.23; 'header :In-Reply-To:1': 0.24; 'chris': 0.26; 'yield': 0.27; 'function': 0.28; 'referencing': 0.29; 'classes': 0.30; "we're": 0.30; 'code': 0.30; 'source': 0.33; 'file': 0.34; 'gets': 0.35; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'received:66': 0.38; 'thank': 0.38; 'well.': 0.40; 'to:addr:python.org': 0.40; 'some': 0.40; 'header:Message-Id:1': 0.61; 'within': 0.64; 'disappears': 0.84 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=bdurham.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=OuvZxnW+cEQ5LJfBPqthQR5PdcE=; b=m7Cuei 8klKdcLuDNLWbEjiay+IVQVQzKIoCULE/cqOP8bequYXv9ZHOFEXzXDeSu0084hc s+6Ds0BUyGLHXORU0w6Gw1F6Si3HgTGUDcGNt/4I/Nl3gQQg/6c1fqNle8eziAMq v4m82om+0BK+KaFlzDI/f3KSZ2JZupP+dRzYM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=OuvZxnW+cEQ5LJf BPqthQR5PdcE=; b=bhsI3nrS5aGzSOVW2NBrpws9Hd/T+s7+vwmxC8D8KBwahQw vWWMaXSpLBllWcVu2wcSsVL5/ObYNO7n0i7JVaVj4W6FRAdDBrYsjbG75RwVHvIZ NglF9c28Bvw51tPeJOq4DwElS1Ipil4aIK3qlbCIHTilesPB9cRCZJXRO+KQ= X-Sasl-Enc: JEF4XXrn71tpojm4Bc0N0uxQlEXHl10uApNr/EUX7rpi 1469117265 X-Mailer: MessagingEngine.com Webmail Interface - ajax-2ccfea0a In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com> X-Mailman-Original-References: <1469112141.379402.672830825.05659985@webmail.messagingengine.com> Xref: csiph.com comp.lang.python:111719 Thank you Chris and Peter. The source file we're generating has one main function (go) with some supporting functions and classes as well. Will there be any problems referencing additional functions or classes defined in the source that gets passed to exec ... as long as references to those functions and classes happen within the generated module? 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? The Python documentation also warns: "Be aware that the return and yield statements may not be used outside of function definitions even within the context of code passed to the exec() function. The return value is None." Malcolm