# Path: pypet/pypetlogging.py
# class HasLogger(HasSlots):
#     """Abstract super class that automatically adds a logger to a class.
# 
#     To add a logger to a sub-class of yours simply call ``myobj._set_logger(name)``.
#     If ``name=None`` the logger is chosen as follows:
# 
#         ``self._logger = logging.getLogger(self.__class.__.__module__ + '.' + self.__class__.__name__)``
# 
#     The logger can be accessed via ``myobj._logger``.
# 
#     """
# 
#     __slots__ = ('_logger',)
# 
#     def __getstate__(self):
#         """Called for pickling.
# 
#         Removes the logger to allow pickling and returns a copy of `__dict__`.
# 
#         """
#         state_dict = super(HasLogger, self).__getstate__()
#         if '_logger' in state_dict:
#             # Pickling does not work with loggers objects,
#             # so we just keep the logger's name:
#             state_dict['_logger'] = self._logger.name
#         return state_dict
# 
#     def __setstate__(self, statedict):
#         """Called after loading a pickle dump.
# 
#         Restores `__dict__` from `statedict` and adds a new logger.
# 
#         """
#         super(HasLogger, self).__setstate__(statedict)
#         if '_logger' in statedict:
#             # If we re-instantiate the component the
#             # logger attribute only contains a name,
#             # so we also need to re-create the logger:
#             self._set_logger(statedict['_logger'])
# 
#     def _set_logger(self, name=None):
#         """Adds a logger with a given `name`.
# 
#         If no name is given, name is constructed as
#         `type(self).__name__`.
# 
#         """
#         if name is None:
#             cls = self.__class__
#             name = '%s.%s' % (cls.__module__, cls.__name__)
#         self._logger = logging.getLogger(name)
# 
# Path: pypet/utils/decorators.py
# def retry(n, errors, wait=0.0, logger_name=None):
#     """This is a decorator that retries a function.
# 
#     Tries `n` times and catches a given tuple of `errors`.
# 
#     If the `n` retries are not enough, the error is reraised.
# 
#     If desired `waits` some seconds.
# 
#     Optionally takes a 'logger_name' of a given logger to print the caught error.
# 
#     """
# 
#     def wrapper(func):
#         @functools.wraps(func)
#         def new_func(*args, **kwargs):
#             retries = 0
#             while True:
#                 try:
#                     result = func(*args, **kwargs)
#                     if retries and logger_name:
#                         logger = logging.getLogger(logger_name)
#                         logger.debug('Retry of `%s` successful' % func.__name__)
#                     return result
#                 except errors:
#                     if retries >= n:
#                         if logger_name:
#                             logger = logging.getLogger(logger_name)
#                             logger.exception('I could not execute `%s` with args %s and kwargs %s, '
#                                              'starting next try. ' % (func.__name__,
#                                                                       str(args),
#                                                                       str(kwargs)))
#                         raise
#                     elif logger_name:
#                         logger = logging.getLogger(logger_name)
#                         logger.debug('I could not execute `%s` with args %s and kwargs %s, '
#                                          'starting next try. ' % (func.__name__,
#                                                                   str(args),
#                                                                   str(kwargs)))
#                     retries += 1
#                     if wait:
#                         time.sleep(wait)
#         return new_func
# 
#     return wrapper
# 
# Path: pypet/utils/helpful_functions.py
# def is_ipv6(url):
#     return '[' in url


from threading import ThreadError
from collections import deque
from threading import Thread
from pypet.pypetlogging import HasLogger
from pypet.utils.decorators import retry
from pypet.utils.helpful_functions import is_ipv6
import queue
import pickle
    import zmq
import copy as cp
import gc
import sys
import time
import os
import socket
import pypet.pypetconstants as pypetconstants
        """Puts data on queue"""
        old = self.pickle_queue
        self.pickle_queue = False
        try:
            self.queue.put(to_put, block=True)
        finally:
            self.pickle_queue = old

    def store(self, *args, **kwargs):
        """Puts data to store on queue.

        Note that the queue will no longer be pickled if the Sender is pickled.

        """
        self._put_on_queue(('STORE', args, kwargs))

    def send_done(self):
        """Signals the writer that it can stop listening to the queue"""
        self._put_on_queue(('DONE', [], {}))


class LockAcquisition(HasLogger):
    """Abstract class to allow lock acquisition and release.

    Assumes that implementing classes have a ``lock``, ``is_locked`` and
    ``is_open`` attribute.

    Requires a ``_logger`` for error messaging.

    """

# Path: pypet/pypetlogging.py
# class HasLogger(HasSlots):
#     """Abstract super class that automatically adds a logger to a class.
# 
#     To add a logger to a sub-class of yours simply call ``myobj._set_logger(name)``.
#     If ``name=None`` the logger is chosen as follows:
# 
#         ``self._logger = logging.getLogger(self.__class.__.__module__ + '.' + self.__class__.__name__)``
# 
#     The logger can be accessed via ``myobj._logger``.
# 
#     """
# 
#     __slots__ = ('_logger',)
# 
#     def __getstate__(self):
#         """Called for pickling.
# 
#         Removes the logger to allow pickling and returns a copy of `__dict__`.
# 
#         """
#         state_dict = super(HasLogger, self).__getstate__()
#         if '_logger' in state_dict:
#             # Pickling does not work with loggers objects,
#             # so we just keep the logger's name:
#             state_dict['_logger'] = self._logger.name
#         return state_dict
# 
#     def __setstate__(self, statedict):
#         """Called after loading a pickle dump.
# 
#         Restores `__dict__` from `statedict` and adds a new logger.
# 
#         """
#         super(HasLogger, self).__setstate__(statedict)
#         if '_logger' in statedict:
#             # If we re-instantiate the component the
#             # logger attribute only contains a name,
#             # so we also need to re-create the logger:
#             self._set_logger(statedict['_logger'])
# 
#     def _set_logger(self, name=None):
#         """Adds a logger with a given `name`.
# 
#         If no name is given, name is constructed as
#         `type(self).__name__`.
# 
#         """
#         if name is None:
#             cls = self.__class__
#             name = '%s.%s' % (cls.__module__, cls.__name__)
#         self._logger = logging.getLogger(name)
# 
# Path: pypet/utils/decorators.py
# def retry(n, errors, wait=0.0, logger_name=None):
#     """This is a decorator that retries a function.
# 
#     Tries `n` times and catches a given tuple of `errors`.
# 
#     If the `n` retries are not enough, the error is reraised.
# 
#     If desired `waits` some seconds.
# 
#     Optionally takes a 'logger_name' of a given logger to print the caught error.
# 
#     """
# 
#     def wrapper(func):
#         @functools.wraps(func)
#         def new_func(*args, **kwargs):
#             retries = 0
#             while True:
#                 try:
#                     result = func(*args, **kwargs)
#                     if retries and logger_name:
#                         logger = logging.getLogger(logger_name)
#                         logger.debug('Retry of `%s` successful' % func.__name__)
#                     return result
#                 except errors:
#                     if retries >= n:
#                         if logger_name:
#                             logger = logging.getLogger(logger_name)
#                             logger.exception('I could not execute `%s` with args %s and kwargs %s, '
#                                              'starting next try. ' % (func.__name__,
#                                                                       str(args),
#                                                                       str(kwargs)))
#                         raise
#                     elif logger_name:
#                         logger = logging.getLogger(logger_name)
#                         logger.debug('I could not execute `%s` with args %s and kwargs %s, '
#                                          'starting next try. ' % (func.__name__,
#                                                                   str(args),
#                                                                   str(kwargs)))
#                     retries += 1
#                     if wait:
#                         time.sleep(wait)
#         return new_func
# 
#     return wrapper
# 
# Path: pypet/utils/helpful_functions.py
# def is_ipv6(url):
#     return '[' in url


# Path: pypet/utils/mpwrappers.py
from threading import ThreadError
from collections import deque
from threading import Thread
from pypet.pypetlogging import HasLogger
from pypet.utils.decorators import retry
from pypet.utils.helpful_functions import is_ipv6
import queue
import pickle
    import zmq
import copy as cp
import gc
import sys
import time
import os
import socket
import pypet.pypetconstants as pypetconstants

        """Puts data on queue"""
        old = self.pickle_queue
        self.pickle_queue = False
        try:
            self.queue.put(to_put, block=True)
        finally:
            self.pickle_queue = old

    def store(self, *args, **kwargs):
        """Puts data to store on queue.

        Note that the queue will no longer be pickled if the Sender is pickled.

        """
        self._put_on_queue(('STORE', args, kwargs))

    def send_done(self):
        """Signals the writer that it can stop listening to the queue"""
        self._put_on_queue(('DONE', [], {}))


class LockAcquisition(HasLogger):
    """Abstract class to allow lock acquisition and release.

    Assumes that implementing classes have a ``lock``, ``is_locked`` and
    ``is_open`` attribute.

    Requires a ``_logger`` for error messaging.

    """

    @retry(9, TypeError, 0.01, 'pypet.retry')