@@ -117,7 +117,8 @@ def id() -> str:
117
117
@property
118
118
def _frontend (self ) -> Pep517VirtualEnvFrontend :
119
119
if self ._frontend_ is None :
120
- self ._frontend_ = Pep517VirtualEnvFrontend (self .root , self )
120
+ fresh = cast (bool , self .conf ["fresh_subprocess" ])
121
+ self ._frontend_ = Pep517VirtualEnvFrontend (self .root , self , fresh_subprocess = fresh )
121
122
return self ._frontend_
122
123
123
124
def register_config (self ) -> None :
@@ -136,6 +137,12 @@ def register_config(self) -> None:
136
137
)
137
138
for key in ("sdist" , "wheel" , "editable" ):
138
139
self ._add_config_settings (key )
140
+ self .conf .add_config (
141
+ keys = ["fresh_subprocess" ],
142
+ of_type = bool ,
143
+ default = False ,
144
+ desc = "create a fresh subprocess for every backend request" ,
145
+ )
139
146
140
147
def _add_config_settings (self , build_type : str ) -> None :
141
148
# config settings passed to PEP-517-compliant build backend https://peps.python.org/pep-0517/#config-settings
@@ -370,9 +377,10 @@ def id() -> str:
370
377
371
378
372
379
class Pep517VirtualEnvFrontend (Frontend ):
373
- def __init__ (self , root : Path , env : Pep517VenvPackager ) -> None :
380
+ def __init__ (self , root : Path , env : Pep517VenvPackager , * , fresh_subprocess : bool ) -> None :
374
381
super ().__init__ (* Frontend .create_args_from_folder (root ))
375
382
self ._tox_env = env
383
+ self ._fresh_subprocess = fresh_subprocess
376
384
self ._backend_executor_ : LocalSubProcessPep517Executor | None = None
377
385
into : dict [str , Any ] = {}
378
386
@@ -412,19 +420,23 @@ def _send_msg(
412
420
result_file : Path , # noqa: ARG002
413
421
msg : str ,
414
422
) -> Iterator [ToxCmdStatus ]:
415
- with self ._tox_env .execute_async (
416
- cmd = self .backend_cmd ,
417
- cwd = self ._root ,
418
- stdin = StdinSource .API ,
419
- show = None ,
420
- run_id = cmd ,
421
- executor = self .backend_executor ,
422
- ) as execute_status :
423
- execute_status .write_stdin (f"{ msg } { os .linesep } " )
424
- yield ToxCmdStatus (execute_status )
425
- outcome = execute_status .outcome
426
- if outcome is not None : # pragma: no branch
427
- outcome .assert_success ()
423
+ try :
424
+ with self ._tox_env .execute_async (
425
+ cmd = self .backend_cmd ,
426
+ cwd = self ._root ,
427
+ stdin = StdinSource .API ,
428
+ show = None ,
429
+ run_id = cmd ,
430
+ executor = self .backend_executor ,
431
+ ) as execute_status :
432
+ execute_status .write_stdin (f"{ msg } { os .linesep } " )
433
+ yield ToxCmdStatus (execute_status )
434
+ outcome = execute_status .outcome
435
+ if outcome is not None : # pragma: no branch
436
+ outcome .assert_success ()
437
+ finally :
438
+ if self ._fresh_subprocess :
439
+ self .backend_executor .close ()
428
440
429
441
def _unexpected_response ( # noqa: PLR0913
430
442
self ,
0 commit comments