This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Make asyncio.__main__ reusable, also adding a preamble feature.
Type: enhancement Stage: patch review
Components: asyncio Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, lschoe, yselivanov
Priority: normal Keywords: patch

Created on 2020-12-03 15:34 by lschoe, last changed 2022-04-11 14:59 by admin.

File name Uploaded Description Edit lschoe, 2020-12-03 15:34 based on
Pull Requests
URL Status Linked Edit
PR 24055 open lschoe, 2021-01-02 09:02
Messages (1)
msg382419 - (view) Author: Berry Schoenmakers (lschoe) * Date: 2020-12-03 15:34
The async REPL introduced in Python 3.8 is very nice for quick tests and experiments, supporting top-level "await" (see 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 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 "".
	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, however, I basically had to copy and make a few changes throughout the code. It works alright, but to take advantage of future improvements to it would be very convenient if becomes reusable. 

With the added feature for specifying a "preamble", programming something like 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)')

The attachment contains the current version of, which to a large extent duplicates code from A couple of, I think, minor changes are applied to make the code reusable, and to add the preamble feature.

Would be nice if is updated in this manner in Python 3.10 such that package developers can tailor it to their needs?
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86723
2021-01-02 22:07:25vstinnersetnosy: - vstinner
2021-01-02 09:02:56lschoesetkeywords: + patch
stage: patch review
pull_requests: + pull_request22889
2020-12-03 15:34:45lschoecreate