B
    ‹æ@\  ã               @   s^   d Z ddlmZmZmZmZ ddlZe e¡Z	ddl
mZ dZdd„ Zd	ZG d
d„ deƒZdS )z

é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsNé   )Úwraps)ÚUnlockedDocumentProxyÚwithout_document_lockc                s   t ˆ ƒ‡ fdd„ƒ}d|_|S )až   Wrap a callback function to execute without first obtaining the
    document lock.

    Args:
        func (callable) : The function to wrap

    Returns:
        callable : a function wrapped to execute without a |Document| lock.

    While inside an unlocked callback, it is completely *unsafe* to modify
    ``curdoc()``. The value of ``curdoc()`` inside the callback will be a
    specially wrapped version of |Document| that only allows safe operations,
    which are:

    * :func:`~bokeh.document.Document.add_next_tick_callback`
    * :func:`~bokeh.document.Document.remove_next_tick_callback`

    Only these may be used safely without taking the document lock. To make
    other changes to the document, you must add a next tick callback and make
    your changes to ``curdoc()`` from that second callback.

    Attempts to otherwise access or change the Document will result in an
    exception being raised.

    c                 s
   ˆ | |ŽS )N© )ÚargsÚkw)Úfuncr
   ú5lib/python3.7/site-packages/bokeh/document/locking.pyÚwrapperE   s    z&without_document_lock.<locals>.wrapperT)r   Znolock)r   r   r
   )r   r   r	   +   s    r	   z¼Only 'add_next_tick_callback' may be used safely without taking the document lock; to make other changes to the document, add a next tick callback and make your changes from that callback.c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )r   zÏ Wrap a Document object so that only methods that can safely be used
    from unlocked callbacks or threads are exposed. Attempts to otherwise
    access or change the Document results in an exception.

    c             C   s
   || _ dS )z


        N)Ú_doc)ÚselfÚdocr
   r
   r   Ú__init__X   s    zUnlockedDocumentProxy.__init__c             C   s   t tƒ‚dS )z


        N)ÚRuntimeErrorÚUNSAFE_DOC_ATTR_USAGE_MSG)r   Úattrr
   r
   r   Ú__getattr__^   s    z!UnlockedDocumentProxy.__getattr__c             C   s   | j  |¡S )zW Add a "next tick" callback.

        Args:
            callback (callable) :

        )r   Úadd_next_tick_callback)r   Úcallbackr
   r
   r   r   d   s    z,UnlockedDocumentProxy.add_next_tick_callbackc             C   s   | j  |¡S )zZ Remove a "next tick" callback.

        Args:
            callback (callable) :

        )r   Úremove_next_tick_callback)r   r   r
   r
   r   r   m   s    z/UnlockedDocumentProxy.remove_next_tick_callbackN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r
   r
   r
   r   r   Q   s
   	r   )r   Z
__future__r   r   r   r   ZloggingZ	getLoggerr   ÚlogZutil.futurer   Ú__all__r	   r   Úobjectr   r
   r
   r
   r   Ú<module>	   s   
!