[Python-Dev] PEP 554 v3 (new interpreters module) (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Sun Oct 8 22:39:28 EDT 2017
- Previous message (by thread): [Python-Dev] PEP 554 v3 (new interpreters module)
- Next message (by thread): [Python-Dev] Make re.compile faster
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 14 September 2017 at 11:44, Eric Snow <ericsnowcurrently at gmail.com> wrote:
Examples ========
Run isolated code ----------------- :: interp = interpreters.create() print('before') interp.run('print("during")') print('after')
A few more suggestions for examples:
Running a module:
main_module = mod_name
interp.run(f"import runpy; runpy.run_module({main_module!r})")
Running as script (including zip archives & directories):
main_script = path_name
interp.run(f"import runpy; runpy.run_path({main_script!r})")
Running in a thread pool executor:
interps = [interpreters.create() for i in range(5)]
with concurrent.futures.ThreadPoolExecutor(max_workers=len(interps)) as
pool: print('before') for interp in interps: pool.submit(interp.run, 'print("starting"); print("stopping")' print('after')
That last one is prompted by the questions about the benefits of keeping the notion of an interpreter state distinct from the notion of a main thread (it allows a single "MainThread" object to be mapped to different OS level threads at different points in time, which means it's easier to combine with existing constructs for managing OS level thread pools).
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171009/ba2764e2/attachment.html>
- Previous message (by thread): [Python-Dev] PEP 554 v3 (new interpreters module)
- Next message (by thread): [Python-Dev] Make re.compile faster
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]