classification
Title: Add a "target" parameter to runpy.run_path and runpy.run_module
Type: enhancement Stage: needs patch
Components: Versions: Python 3.8
process
Status: open Resolution:
Dependencies: 19700 Superseder:
Assigned To: Nosy List: CuriousLearner, brett.cannon, eric.snow, nanjekyejoannah, ncoghlan, piotr.dobrogost
Priority: normal Keywords:

Created on 2013-12-14 13:22 by ncoghlan, last changed 2019-08-06 17:38 by nanjekyejoannah.

Messages (5)
msg206181 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-12-14 13:22
One idea from PEP 451 was to add a "target" parameter to runpy.run_path and runpy.run_module to allow them to support execution in an existing module namespace (like __main__).

This missed the feature freeze deadline for 3.4, but can be added in 3.5.
msg206430 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-12-17 12:48
Implementing this is actually likely to require non-trivial restructuring of the runpy internals. contextlib.ExitStack may prove useful in making it easier to programmatically select amongst different context managers.

The __mp_main__ helpers in multiprocessing should also be able to take advantage of this once it is available, and it may prove useful in finally providing -m analogues for pdb etc that play nice when an exception occurs (see issue 9325).
msg305671 - (view) Author: Sanyam Khurana (CuriousLearner) * (Python triager) Date: 2017-11-06 19:45
Hey ncoghlan,

Does this issue makes sense to be worked on for Python 3.7?
msg305719 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2017-11-07 07:57
See issue 21862 and issue 9325 as potential use cases for this feature.

While it looks like issue 21862 (-m switch support in cProfile) can be implemented just fine without it, this feature will be needed for the modules that execute the given scripts directly in __main__.__dict__ (e.g. pdb).
msg349121 - (view) Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) Date: 2019-08-06 17:38
issue 19978 also needs this.
History
Date User Action Args
2019-08-06 17:38:32nanjekyejoannahsetmessages: + msg349121
2019-06-20 18:19:47nanjekyejoannahsetnosy: + nanjekyejoannah
2018-06-04 12:58:12ncoghlansetversions: + Python 3.8, - Python 3.7
2017-11-07 07:57:46ncoghlansetversions: + Python 3.7, - Python 3.5
2017-11-07 07:57:38ncoghlansetmessages: + msg305719
2017-11-06 19:45:00CuriousLearnersetnosy: + CuriousLearner
messages: + msg305671
2016-02-22 09:26:51piotr.dobrogostsetnosy: + piotr.dobrogost
2013-12-17 12:48:44ncoghlansetmessages: + msg206430
2013-12-14 13:22:30ncoghlanlinkissue19978 dependencies
2013-12-14 13:22:13ncoghlansetdependencies: + Update runpy for PEP 451
2013-12-14 13:22:03ncoghlancreate