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.

classification
Title: Make asyncio.__main__ reusable, also adding a preamble feature.
Type: enhancement Stage: patch review
Components: asyncio Versions: Python 3.10
process
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.

Files
File name Uploaded Description Edit
__main__.py lschoe, 2020-12-03 15:34 mpyc.__main__.py based on asyncio.__main__.py
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 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?
History
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