Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #111715
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Malcolm Greene <python@bdurham.com> |
| Newsgroups | comp.lang.python |
| Subject | Technique for safely reloading dynamically generated module |
| Date | Thu, 21 Jul 2016 10:42:21 -0400 |
| Lines | 31 |
| Message-ID | <mailman.25.1469112144.22221.python-list@python.org> (permalink) |
| References | <1469112141.379402.672830825.05659985@webmail.messagingengine.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de 07qGlMD6Sgn3LTokAzG90QfxIaJTh/ERhAdzUROgAiVA== |
| Return-Path | <python@bdurham.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'received:internal': 0.09; 'subject:module': 0.09; 'python': 0.10; 'file,': 0.15; 'compile,': 0.16; 'from:addr:python': 0.16; 'language)': 0.16; 'malcolm': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'missing,': 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; 'reload': 0.16; 'sys.path': 0.16; 'true:': 0.16; 'runs': 0.18; 'visible': 0.22; 'code.': 0.23; 'import': 0.24; 'module': 0.25; "we're": 0.30; 'code': 0.30; 'run': 0.33; 'source': 0.33; 'file': 0.34; 'server': 0.34; 'step': 0.36; 'there': 0.36; 'created': 0.36; 'to:addr:python-list': 0.36; 'received:10': 0.37; 'associated': 0.38; 'received:66': 0.38; 'version': 0.38; 'thank': 0.38; 'application': 0.39; 'to:addr:python.org': 0.40; 'header :Message-Id:1': 0.61; 'our': 0.64; 'techniques': 0.65; 'dsl': 0.84; 'of?': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d=bdurham.com; h= content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=wf9 JlLV6XyIZTWvRE9Mfns5IMBI=; b=Knf+M4ru/Qry0dlfrEwsaciEB8kPXM+7xp/ NcvQdM54z8ydUaWMWDWlJXWKLuIXIqdBshOAIwM97jtuSsfSwctxZKFzXaZgTu8S 0LZBOmlhMJncIEi8+2vcppz2BXSNg6uR6R4kCL5oEFvKIlQ9kNhs1lUc5y2OReRC lKTpjyCc= |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=wf9JlLV6XyIZTWvRE9Mfns5IMBI=; b=K1fss F66GUVJ9Ww/W77+yOts0A8AdQNgCeZ5mv6HaafTZ+Mospp8/exmkf96KwLa8kb7+ x2itLIjFwjxIuqifxkOpmgeFEbCeBS3Q/Nr15TTnqvfNb7C7GOhY5qHeipjFJ66H OBYYEP7TpnR91FqlbNFbTBviGjpQmtjWAcPMiY= |
| X-Sasl-Enc | Sri+p4pJll5wRGX1jvjPR6oqdM8Ljq3bNMf2l2WzgU5w 1469112141 |
| X-Mailer | MessagingEngine.com Webmail Interface - ajax-2ccfea0a |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.22 |
| 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 | <1469112141.379402.672830825.05659985@webmail.messagingengine.com> |
| Xref | csiph.com comp.lang.python:111715 |
Show key headers only | View raw
We're designing a server application that parses a custom DSL (domain
specific language) source file, generates a Python module with the
associated logic, and runs the associated code. Since this is a server
application, we need to reload the module after each regeneration. Is
this process is simple as the following pseudo code or are there other
issues we need to be aware of? Are there better techniques for this
workflow (eval, compile, etc)?
We're working in Python 3.5.1.
import importlib
# custom_code is the module our code will generate - a version of this
# file will always be present
# if custom_code.py is missing, a blank version of this file is created
# before this step
import custom_code
while True:
# (re)generates custom_code.py visible in sys.path
generate_custom_code( source_file )
# reload the module whose source we just generated
importlib.reload( custom_code )
# run the main code in generated module
custom_code.go()
Thank you,
Malcolm
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Technique for safely reloading dynamically generated module Malcolm Greene <python@bdurham.com> - 2016-07-21 10:42 -0400
csiph-web