<commit_before># coding: utf-8

#import cPickle as pickle
#from ctypes import *
#from _ctypes import *

from _cffi import C, ffi
from constants import *
from error import *
from utils import jsonapi

class Context(object):
    _state = {}
    def __init__(self, iothreads=1):
        if not iothreads > 0:
            raise ZMQError(EINVAL)

        self.__dict__ = self._state

        self.zmq_ctx = C.zmq_init(iothreads)
        self.iothreads = iothreads
        self._closed = False
        self.n_sockets = 0
        self.max_sockets = 32
        self._sockets = {}

    def term(self):
        for k, s in self._sockets.items():
            if not s.closed:
                s.close()
                self._rm_socket(k)
                self.n_sockets -= 1

        C.zmq_term(self.zmq_ctx)
        self.zmq_ctx = None
        self._closed = True

    @property
    def closed(self):
        return self._closed

    def _add_socket(self, socket):
        self._sockets[self.n_sockets] = socket
        self.n_sockets += 1<commit_msg>clear sockets dict and set socket number to 0<commit_after># coding: utf-8

#import cPickle as pickle
#from ctypes import *
#from _ctypes import *

from _cffi import C, ffi
from constants import *
from error import *
from utils import jsonapi

class Context(object):
    _state = {}
    def __init__(self, iothreads=1):
        if not iothreads > 0:
            raise ZMQError(EINVAL)

        self.__dict__ = self._state

        self.zmq_ctx = C.zmq_init(iothreads)
        self.iothreads = iothreads
        self._closed = False
        self.n_sockets = 0
        self.max_sockets = 32
        self._sockets = {}

    def term(self):
        for k, s in self._sockets.items():
            if not s.closed:
                s.close()

        C.zmq_term(self.zmq_ctx)
        self.n_sockets = 0
        self._sockets = {}
        self.zmq_ctx = None
        self._closed = True

    @property
    def closed(self):
        return self._closed

    def _add_socket(self, socket):
        self._sockets[self.n_sockets] = socket
        self.n_sockets += 1
{'fraction_non_alphanumeric': 0.08982322025800286, 'fraction_numerical': 0.008122312470138558, 'mean_word_length': 1.9914285714285713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '295960', 'n_tokens_mistral': 715, 'n_tokens_neox': 674, 'n_words': 175}