# Path: carbono/buffer_manager/reorder_buffer.py
# class ReoderBuffer(object):
#     def __init__(self, out_buffer, size=10):
#         self.out_buffer = out_buffer
#         self.size = size
#         self._array = Manager().list(range(self.size))
#         self._lock = Lock()
#         self._min = 0
#         self._max = self.size
#         self._count = 0
#         self.update_control()
# 
#     def update_control(self):
#         self._control = dict()
#         for e, i in enumerate(xrange(self._min, self._max)):
#             self._control.update({i: e})
# 
#     def put(self, block_num, data):
#         self._lock.acquire()
#         if block_num not in self._control.keys():
#             self._lock.release()
#             raise IndexError
#         self._array[self._control[block_num]] = data
#         self._count += 1
#         if self._count == self.size: self.sync()
#         self._lock.release()
# 
#     def sync(self):
#         for i in xrange(self._count):
#             data = self._array[i]
#             self.out_buffer.put(data)
#         self._min += self._count
#         self._max += self._count
#         self._count = 0
#         self.update_control()


import time
import Queue
from multiprocessing import Process, Manager, Event
from multiprocessing.managers import BaseManager
from threading import Thread
from copy import deepcopy
from carbono.buffer_manager.reorder_buffer import ReoderBuffer
from carbono.utils import *
from carbono.config import *
from carbono.exception import *
                self._input_buffer.put((deepcopy(self._block_number), data),
                                       timeout=1)
            except Queue.Full:
                continue
            self._block_number += 1
            break

    def _finish(self):
        self.active = False

        for worker in self._worker_list:
            self._input_buffer.put((EOF, EOF))

        for worker in self._worker_list:
            try:
                worker.join()
            except AssertionError:
                pass

        self.reorder_buffer.sync()
        self.output_buffer.put(EOF)
        
    def stop(self):
        self.active = False

        for worker in self._worker_list:
            worker.stop()

        for worker in self._worker_list:
            try:

# Path: carbono/buffer_manager/reorder_buffer.py
# class ReoderBuffer(object):
#     def __init__(self, out_buffer, size=10):
#         self.out_buffer = out_buffer
#         self.size = size
#         self._array = Manager().list(range(self.size))
#         self._lock = Lock()
#         self._min = 0
#         self._max = self.size
#         self._count = 0
#         self.update_control()
# 
#     def update_control(self):
#         self._control = dict()
#         for e, i in enumerate(xrange(self._min, self._max)):
#             self._control.update({i: e})
# 
#     def put(self, block_num, data):
#         self._lock.acquire()
#         if block_num not in self._control.keys():
#             self._lock.release()
#             raise IndexError
#         self._array[self._control[block_num]] = data
#         self._count += 1
#         if self._count == self.size: self.sync()
#         self._lock.release()
# 
#     def sync(self):
#         for i in xrange(self._count):
#             data = self._array[i]
#             self.out_buffer.put(data)
#         self._min += self._count
#         self._max += self._count
#         self._count = 0
#         self.update_control()


# Path: carbono/buffer_manager/work_manager.py
import time
import Queue
from multiprocessing import Process, Manager, Event
from multiprocessing.managers import BaseManager
from threading import Thread
from copy import deepcopy
from carbono.buffer_manager.reorder_buffer import ReoderBuffer
from carbono.utils import *
from carbono.config import *
from carbono.exception import *

                self._input_buffer.put((deepcopy(self._block_number), data),
                                       timeout=1)
            except Queue.Full:
                continue
            self._block_number += 1
            break

    def _finish(self):
        self.active = False

        for worker in self._worker_list:
            self._input_buffer.put((EOF, EOF))

        for worker in self._worker_list:
            try:
                worker.join()
            except AssertionError:
                pass

        self.reorder_buffer.sync()
        self.output_buffer.put(EOF)
        
    def stop(self):
        self.active = False

        for worker in self._worker_list:
            worker.stop()

        for worker in self._worker_list:
            try:

                worker.join()