def __init__(self, addresses, size=5): self.log = logging.getLogger(__name__) self._addresses = addresses self._semaphore = lock.BoundedSemaphore(size) self._socket_queue = queue.LifoQueue(size) self.connection_timeout = DEFAULT_CONNECTION_TIMEOUT self.network_timeout = DEFAULT_NETWORK_TIMEOUT self.size = size self._blacklist = list() self._bl_semaphore = lock.BoundedSemaphore(1)
def __init__(self, ip, port, socket_num=DEFAULT_CONNECT_SIZE, is_async=False, network_timeout=DEFAULT_TIMEOUT): self._ip = ip self._port = port self._timeout = network_timeout self._num = socket_num self._closed = False self._async = is_async if self._async: import gevent.queue try: from gevent import lock as glock except ImportError: from gevent import coros as glock self._semaphore = glock.BoundedSemaphore(socket_num) self._connection_queue = gevent.queue.LifoQueue(socket_num) self._QueueEmpty = gevent.queue.Empty else: import threading try: import Queue except ImportError: import queue as Queue self._semaphore = threading.BoundedSemaphore(socket_num) self._connection_queue = Queue.LifoQueue(socket_num) self._QueueEmpty = Queue.Empty
def __init__(self, host, port, iface_cls, size=DEFAULT_POOL_SIZE, asyn=False, network_timeout=DEFAULT_NETWORK_TIMEOUT): self.host = host self.port = port self.iface_cls = iface_cls self.network_timeout = network_timeout self.size = size self._closed = False self._async = asyn if self._async: import gevent.queue try: from gevent import lock as glock except ImportError: # gevent < 1.0 from gevent import coros as glock self._semaphore = glock.BoundedSemaphore(size) self._connection_queue = gevent.queue.LifoQueue(size) self._QueueEmpty = gevent.queue.Empty else: import threading import queue self._semaphore = threading.BoundedSemaphore(size) self._connection_queue = queue.LifoQueue(size) self._QueueEmpty = queue.Empty
def __init__(self, connection_host, connection_port, request_host, request_port, size=5, disable_ipv6=False, connection_timeout=DEFAULT_CONNECTION_TIMEOUT, network_timeout=DEFAULT_NETWORK_TIMEOUT, use_proxy=False): self._closed = False self._connection_host = connection_host self._connection_port = connection_port self._request_host = request_host self._request_port = request_port self._semaphore = lock.BoundedSemaphore(size) self._socket_queue = gevent.queue.LifoQueue(size) self._use_proxy = use_proxy if use_proxy: self.__proxy = '{self._connection_host}:{self._connection_port}'\ .format(self=self) self.connection_timeout = connection_timeout self.network_timeout = network_timeout self.size = size self.disable_ipv6 = disable_ipv6
def __init__(self, host, port, size=5, disable_ipv6=False, connection_timeout=DEFAULT_CONNECTION_TIMEOUT, network_timeout=DEFAULT_NETWORK_TIMEOUT): self._closed = False self._host = host self._port = port self._semaphore = lock.BoundedSemaphore(size) self._socket_queue = gevent.queue.LifoQueue(size) self.connection_timeout = connection_timeout self.network_timeout = network_timeout self.size = size self.disable_ipv6 = disable_ipv6
self.port = port self.iface_cls = iface_cls self.network_timeout = network_timeout self.size = size self._closed = False self._async = async if self._async: import gevent.queue try: from gevent import lock as glock except ImportError: # gevent < 1.0 from gevent import coros as glock self._semaphore = glock.BoundedSemaphore(size) self._connection_queue = gevent.queue.LifoQueue(size) self._QueueEmpty = gevent.queue.Empty else: import threading import Queue self._semaphore = threading.BoundedSemaphore(size) self._connection_queue = Queue.LifoQueue(size) self._QueueEmpty = Queue.Empty def close(self): self._closed = True while not self._connection_queue.empty(): try: conn = self._connection_queue.get(block=False)
from flask import Flask, render_template from flask_socketio import SocketIO, emit from flask_socketio import join_room, leave_room from flask import render_template, copy_current_request_context, request from main import url_details, fetch_episode, write_to_file, \ create_folder app = Flask(__name__) app.debug = True socketio = SocketIO(app, debug=True, async_mode="gevent") ready_to_download = {} MAX_WORKERS = 4 workers = lock.BoundedSemaphore(MAX_WORKERS) queue = Queue() threads = [] DOWNLOAD_DIR = "/mnt/downloads/sdarot/" def back_thread(): while True: func, room_id, url = queue.get() func(room=room_id, url=url) @socketio.on('connect')