@@ -68,7 +68,7 @@ def set_return_code(self, rc: int):
6868 with open (self ._rc_file , "w" ) as f :
6969 f .write (f"{ rc } " )
7070
71- def _set_raw_name (self , raw_name : Optional [str ]):
71+ def _set_raw_name (self , raw_name : Optional [str ]) -> None :
7272 """
7373 Set name for the first time on hap creation.
7474 """
@@ -110,7 +110,7 @@ def _set_pid(self, pid: int):
110110 if not psutil .pid_exists (pid ):
111111 raise RuntimeError (f"Process with pid { pid } is gone" )
112112
113- def _set_logfiles (self , redirect_stderr : bool ):
113+ def _set_logfiles (self , redirect_stderr : bool ) -> None :
114114 if redirect_stderr :
115115 logger .debug ("Process stderr will be redirected to stdout file" )
116116 if not self ._stdout_path .exists () and not redirect_stderr :
@@ -127,12 +127,16 @@ def _get_proc_env(self) -> Dict[str, str]:
127127 logger .error (f"Cannot get environment: { e } " )
128128 return environ
129129
130- def _set_env (self , env : Optional [Dict [str , str ]] = None ):
131- if env is None :
132- env = dict (os .environ )
130+ def _set_env (self , env : Optional [Dict [str , str ]] = None ) -> None :
131+ """
132+ Set environment variables for the first time on hap creation.
133+ """
134+ if self .env is None :
135+ if env is None :
136+ env = dict (os .environ )
133137
134- with open (self ._env_file , "w" ) as env_file :
135- env_file .write (json .dumps (env ))
138+ with open (self ._env_file , "w" ) as env_file :
139+ env_file .write (json .dumps (env ))
136140
137141 def bind (self , pid : int ):
138142 """
@@ -247,10 +251,7 @@ def pid(self) -> Optional[int]:
247251 @property
248252 @allow_missing
249253 def env (self ) -> Optional [Dict [str , str ]]:
250- proc = self .proc
251- environ = {}
252- if proc is not None :
253- environ = proc .environ ()
254+ environ = self ._get_proc_env ()
254255
255256 if environ :
256257 return environ
0 commit comments