
    h                    |    S r SSKJr  SSKrSSKrSSKJr  SSKJr  SS/r	 " S S5      r
\R                  S	 5       rg)
zMiscellaneous utilities.    )annotationsN)Callable)EnvCloudpickleWrapperclear_mpi_env_varsc                  4    \ rS rSrSrS	S jrS rS rS rSr	g)
r      z@Wrapper that uses cloudpickle to pickle and unpickle the result.c                    Xl         g)z#Cloudpickle wrapper for a function.Nfn)selfr   s     U/home/james-whalen/.local/lib/python3.13/site-packages/gymnasium/vector/utils/misc.py__init__CloudpickleWrapper.__init__   s        c                @    SSK nUR                  U R                  5      $ )z1Get the state using `cloudpickle.dumps(self.fn)`.r   N)cloudpickledumpsr   )r   r   s     r   __getstate__CloudpickleWrapper.__getstate__   s      ))r   c                8    SSK nUR                  U5      U l        g)zSets the state with obs.r   N)pickleloadsr   )r   obr   s      r   __setstate__CloudpickleWrapper.__setstate__   s    ,,r"r   c                "    U R                  5       $ )z/Calls the function `self.fn` with no arguments.r   )r   s    r   __call__CloudpickleWrapper.__call__"   s    wwyr   r   N)r   zCallable[[], Env])
__name__
__module____qualname____firstlineno____doc__r   r   r   r   __static_attributes__ r   r   r   r      s    J*#r   c               #  l  #    0 n [        [        R                  R                  5       5       H;  u  pS H0  nUR	                  U5      (       d  M  X U'   [        R                  U	 M2     M=      Sv   [        R                  R                  U 5        g! [        R                  R                  U 5        f = f7f)a  Clears the MPI of environment variables.

``from mpi4py import MPI`` will call ``MPI_Init`` by default.
If the child process has MPI environment variables, MPI will think that the child process
is an MPI process just like the parent and do bad things such as hang.

This context manager is a hacky way to clear those environment variables
temporarily such as when we are starting multiprocessing Processes.

Yields:
    Yields for the context manager
)OMPI_PMI_N)listosenvironitems
startswithupdate)removed_environmentkvprefixs       r   r   r   '   s      RZZ%%'('F||F##)*A&JJqM ( )
/


-.

-.s$   AB4B4,B 0 B4!B11B4)r$   
__future__r   
contextlibr+   collections.abcr   gymnasium.corer   __all__r   contextmanagerr   r&   r   r   <module>r:      sH     "  	 $   !5
6 0 / /r   