New submission from Berry Schoenmakers <l.a.m.schoenmak...@tue.nl>:
The async REPL introduced in Python 3.8 is very nice for quick tests and experiments, supporting top-level "await" (see https://bugs.python.org/issue37028). I'm using it often when developing code that heavily relies on Python's asyncio module. A drawback of the basic interface when launching it with "python -m asyncio" is that one usually still needs to enter a couple of statements to load the package you're working on, etc. To overcome this I've added a __main__.py to the mpyc package such that entering "python -m mpyc" will launch the async REPL like this: asyncio REPL 3.10.0a2 (tags/v3.10.0a2:114ee5d, Nov 3 2020, 00:37:42) [MSC v.1927 64 bit (AMD64)] on win32 Use "await" directly instead of "asyncio.run()". Type "help", "copyright", "credits" or "license" for more information. >>> import asyncio >>> from mpyc.runtime import mpc >>> secint = mpc.SecInt() >>> secfxp = mpc.SecFxp() >>> secfld256 = mpc.SecFld(256) >>> This enables the async REPL but also a "preamble" with some additional code is executed. To program mpyc.__main__.py, however, I basically had to copy asyncio.__main__.py and make a few changes throughout the code. It works alright, but to take advantage of future improvements to asyncio.__main__.py it would be very convenient if asyncio.__main__.py becomes reusable. With the added feature for specifying a "preamble", programming something like mpyc.__main__.py requires just a few lines of code: import asyncio.__main__ if __name__ == '__main__': preamble = ('from mpyc.runtime import mpc', 'secint = mpc.SecInt()', 'secfxp = mpc.SecFxp()', 'secfld256 = mpc.SecFld(256)') asyncio.__main__.main(preamble) The attachment contains the current version of mpyc.__main__.py, which to a large extent duplicates code from asyncio.__main__.py. A couple of, I think, minor changes are applied to make the code reusable, and to add the preamble feature. Would be nice if asyncio.__main__.py is updated in this manner in Python 3.10 such that package developers can tailor it to their needs? ---------- components: asyncio files: __main__.py messages: 382419 nosy: asvetlov, lschoe, vstinner, yselivanov priority: normal severity: normal status: open title: Make asyncio.__main__ reusable, also adding a preamble feature. type: enhancement versions: Python 3.10 Added file: https://bugs.python.org/file49652/__main__.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42557> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com