Ejemplo n.º 1
0
 def test_keyboard_interrupt_stderr_patched(self):
     from gevent import monkey
     monkey.patch_sys(stdin=False, stdout=False, stderr=True)
     try:
         try:
             self.start(raise_, KeyboardInterrupt)
             while True:
                 gevent.sleep(0.1)
         except KeyboardInterrupt:
             pass  # expected
     finally:
         sys.stderr = monkey.get_original('sys', 'stderr')
Ejemplo n.º 2
0
 def test_keyboard_interrupt_stderr_patched(self):
     from gevent import monkey
     monkey.patch_sys(stdin=False, stdout=False, stderr=True)
     try:
         try:
             self.start(raise_, KeyboardInterrupt)
             while True:
                 gevent.sleep(0.1)
         except KeyboardInterrupt:
             pass # expected
     finally:
         sys.stderr = monkey.get_original('sys', 'stderr')
 def test_keyboard_interrupt_stderr_patched(self):
     # XXX: This one non-top-level call prevents us from being
     # run in a process with other tests.
     from gevent import monkey
     monkey.patch_sys(stdin=False, stdout=False, stderr=True)
     try:
         try:
             self.start(raise_, KeyboardInterrupt)
             while True:
                 gevent.sleep(0.1)
         except KeyboardInterrupt:
             pass # expected
     finally:
         sys.stderr = monkey.get_original('sys', 'stderr')
Ejemplo n.º 4
0
def stdin_loop():
    """Global loop: wait for sys.stdin and put line from it to global queue."""
    logging.debug('executing stdin_loop function')
    win = os.name == 'nt'
    while True:
        try:
            # wait_read doesn't work on windows
            if win:
                from gevent import monkey
                monkey.patch_sys()
                l = sys.stdin.readline()
            else:
                wait_read(sys.stdin.fileno())
                l = sys.stdin.readline()
            if l:
                logging.debug('message from sys.stdin: %s', l)
                stdin_queue.put_nowait(l)
        except AttributeError:
            logging.error("can't process sys.stdout", exc_info=True)
            break
Ejemplo n.º 5
0
from exchange.data_proxy import DataProxy

import datetime
import dateutil.parser
import time
import pandas as pd
import gevent
from gevent import monkey

monkey.patch_time()
monkey.patch_socket()
monkey.patch_signal()
monkey.patch_os()

monkey.patch_dns()
monkey.patch_sys()

from exchange.data_proxy import DataProxy

SPREAD_THRESHOLD = 0.1


def on_tick(pair, exchange):
    my_sell_order = 0
    my_buy_order = 0
    # run in loop outside 3s/tick
    data_api = DataProxy(exchange)
    order_slice = data_api.order_books(pair, 100)['result']
    print(order_slice)
    buy_orders = order_slice['buy']
    sell_orders = order_slice['sell']
Ejemplo n.º 6
0
def main():
    """
    Start a Keithley console

    The following example will start a Keithley console with one Keithley
    instrument called *k*::

        $ python -m Salsa.controllers.keithley gpib --pad=15 enet://gpibhost

        keithley> print( k['*IDN?'] )

     """

    import sys
    import argparse
    
    try:
        import serial
    except:
        serial = None

    parser = argparse.ArgumentParser(description=main.__doc__)

    parser.add_argument('--log-level', type=str, default='info',
                        choices=['debug', 'info', 'warning', 'error'],
                        help='log level [default: info]')
    parser.add_argument('--scpi-log-level', type=str, default='info',
                        choices=['trace', 'debug', 'info', 'warning', 'error'],
                        help='log level for scpi object[default: info]')
    parser.add_argument('--keithley-log-level', type=str, default='info',
                        choices=['trace', 'debug', 'info', 'warning', 'error'],
                        help='log level for keithley object[default: info]')
    parser.add_argument('--gevent', action='store_true', default=False,
                        help='enable gevent in console [default: False]')

    subparsers = parser.add_subparsers(title='connection', dest='connection',
                                       description='valid type of connections',
                                       help='choose one type of connection')
    
    gpib_parser = subparsers.add_parser('gpib', help='GPIB connection')
    add = gpib_parser.add_argument
    add('url', type=str, 
        help='gpib instrument url (ex: gpibhost, enet://gpibhost:5000)')
    add('--pad', type=int, required=True, help='primary address')
    add('--sad', type=int, default=0, help='secondary address [default: 0]')
    add('--tmo', type=int, default=10,
        help='gpib timeout (gpib tmo unit) [default: 11 (=1s)]')
    add('--eos', type=str, default='\n', help=r"end of string [default: '\n']")
    add('--timeout', type=float, default=1.1, 
        help='socket timeout [default: 1.1]')

    if serial:
        serial_parser = subparsers.add_parser('serial', 
                                              help='serial line connection')
        add = serial_parser.add_argument
        add('port', type=str, 
            help='serial instrument port (ex: rfc2217://.., ser2net://..)')
        add('--baudrate', type=int, default=9600, help='baud rate')
        add('--bytesize', type=int, choices=[6, 7, 8],
            default=serial.EIGHTBITS, help='byte size')
        add('--parity', choices=serial.PARITY_NAMES.keys(),
            default=serial.PARITY_NONE, help='parity type')
        add('--timeout', type=float, default=5, help='timeout')
        add('--stopbits', type=float, choices=[1, 1.5, 2],
            default=serial.STOPBITS_ONE, help='stop bits')
        add('--xonxoff', action='store_true', default=False, help='')
        add('--rtscts', action='store_true', default=False, help='')
        add('--write-timeout', dest='writeTimeout', type=float, default=None, 
            help='')
        add('--dsrdtr', action='store_true', default=False, help='')
        add('--interchar-timeout', dest='interCharTimeout', type=float, 
            default=None, help='')
        add('--eol', type=str, default='\n',
            help="end of line [default: '\\n']")

    args = parser.parse_args()
    vargs = vars(args)
    
    log_level = getattr(logging, vargs.pop('log_level').upper())
    keithley_log_level = vargs.pop('keithley_log_level').upper()
    scpi_log_level = vargs.pop('scpi_log_level').upper()
    logging.basicConfig(level=log_level,
                        format='%(asctime)s %(levelname)s %(name)s: %(message)s')
    gevent_arg = vargs.pop('gevent')

    conn = vargs.pop('connection')
    kwargs = { conn: vargs }
    mode = not gevent_arg and 'interactive, no gevent' or 'gevent'
    keithley = KeithleyScpi(**kwargs)
    keithley._logger.setLevel(keithley_log_level)
    keithley.language._logger.setLevel(scpi_log_level)
    local = dict(k=keithley)
    banner = '\nWelcome to Keithley console ' \
             '(connected to {0}) ({1})\n'.format(keithley, mode)

    sys.ps1 = 'keithley> '
    sys.ps2 = len(sys.ps1)*'.'

    if gevent_arg:
        try:
            from gevent.monkey import patch_sys
        except ImportError:
            mode = 'no gevent'
        else:
            patch_sys()

    import code
    code.interact(banner=banner, local=local)
Ejemplo n.º 7
0
#!/usr/bin/env python
import os
import sys
from gevent import monkey#; monkey.patch_all()
monkey.patch_os()
monkey.patch_time()
monkey.patch_thread( _threading_local=False)
monkey.patch_sys()
monkey.patch_socket()
monkey.patch_select()
monkey.patch_ssl()
monkey.patch_subprocess()

from psycogreen.gevent import patch_psycopg; patch_psycopg();

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "geventpooltest.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)
Ejemplo n.º 8
0
#!/usr/bin/env python

from gevent import monkey
monkey.patch_all()
monkey.patch_sys(stdin=True, stdout=False, stderr=False)
import gevent
from gevent.queue import Queue
import signal
import sys
from socketio.namespace import BaseNamespace
from socketio.mixins import BroadcastMixin

from formatter import process_log
from web_server import make_server
import random
import datetime


q = Queue()

from anypubsub import create_pubsub

pubsub = create_pubsub('memory')

EQUIPS = ['RE002', 'RE003', 'RE004']

def gettimestr():
    t = datetime.datetime.now()
    return t.strftime('%Y-%m-%d %H:%M:%S')

def producer():
Ejemplo n.º 9
0
Archivo: main.py Proyecto: danlg/zato
Licensed under LGPLv3, see LICENSE.txt for terms and conditions.
"""

from __future__ import absolute_import, division, print_function, unicode_literals

# Monkey-patching modules individually can be about 20% faster,
# or, in absolute terms, instead of 275 ms it may take 220 ms.
from gevent.monkey import patch_builtins, patch_contextvars, patch_thread, patch_time, patch_os, patch_queue, patch_select, \
     patch_selectors, patch_signal, patch_socket, patch_ssl, patch_subprocess, patch_sys

# Note that the order of patching matters, just like in patch_all
patch_os()
patch_time()
patch_thread()
patch_sys()
patch_socket()
patch_select()
patch_selectors()
patch_ssl()
patch_subprocess()
patch_builtins()
patch_signal()
patch_queue()
patch_contextvars()

# stdlib
import locale
import logging
import os
import ssl
Ejemplo n.º 10
0
from gevent import monkey
monkey.patch_all(sys=True)
monkey.patch_sys(stdin=True, stdout=False, stderr=False)

import grpc
import grpc.experimental.gevent as grpc_gevent
grpc_gevent.init_gevent()

import time

import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), *(['..' + os.sep] * 2))))

from gevent.fileobject import FileObject
sys.stdin = FileObject(sys.stdin)

import gevent
from concurrent import futures
import stock_provider_pb2_grpc
import stock_provider_pb2 as sp
from datetime import datetime, timedelta

from google.protobuf import timestamp_pb2
from google.protobuf.empty_pb2 import Empty

_STUB = None
stock_dict = {}
bidask_dict = {}
ba_array = {}
Ejemplo n.º 11
0
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
#

from wishbone import Actor
from os import getpid
from colorama import init, Fore, Back, Style
from gevent.monkey import patch_sys; patch_sys(stdin=True, stdout=True, stderr=True)
import sys


class Format():

    def __init__(self, complete, counter, pid):
        if complete:
            self.complete = self.__returnComplete
        else:
            self.complete = self.__returnIncomplete
        if counter:
            self.counter = self.__returnCounter
        else:
            self.counter = self.__returnNoCounter
        if pid:
Ejemplo n.º 12
0
def main(argv=None):
    """
    Start a SCPI console

    The following example will start a SCPI console with one SCPI instrument
    called *s*::

        $ python -m bliss.comm.scpi gpib --pad=15 enet://gpibhost

        scpi> print s['*IDN']
    """

    import sys
    import argparse

    try:
        import serial
    except:
        serial = None

    parser = argparse.ArgumentParser(description=main.__doc__)

    parser.add_argument('--log-level', type=str, default='info',
                        choices=['trace', 'debug', 'info', 'warning', 'error'],
                        help='global log level [default: info]')
    parser.add_argument('--scpi-log-level', type=str, default='info',
                        choices=['trace', 'debug', 'info', 'warning', 'error'],
                        help='log level for scpi object[default: info]')
    parser.add_argument('--gevent', action='store_true', default=False,
                        help='enable gevent in console [default: False]')

    subparsers = parser.add_subparsers(title="connection", dest="connection",
                                       description="valid type of connections",
                                       help="choose one type of connection")

    gpib_parser = subparsers.add_parser('gpib', help='GPIB connection')
    add = gpib_parser.add_argument
    add('url', type=str,
        help='gpib instrument url (ex: gpibhost, enet://gpibhost:5000)')
    add('--pad', type=int, required=True, help='primary address')
    add('--sad', type=int, default=0, help='secondary address [default: 0]')
    add('--tmo', type=int, default=10,
        help='gpib timeout (gpib tmo unit) [default: 10 (=300ms)]')
    add('--eos', type=str, default='\n', help=r"end of string [default: '\n']")
    add('--timeout', type=float, default=0.4,
        help='socket timeout [default: 0.4]')

    tcp_parser = subparsers.add_parser('tcp', help='TCP connection')
    add = tcp_parser.add_argument
    add('url', type=str,
        help='tcp instrument url (ex: host:5000, socket://host:5000)')
    add('--timeout', type=float, default=5, help='timeout')
    add('--eol', type=str, default='\n',
        help=r"end of line [default: '\n']")

    if serial:
        serial_parser = subparsers.add_parser('serial',
                                              help='serial line connection')
        add = serial_parser.add_argument
        add('port', type=str,
            help='serial instrument port (ex: rfc2217://.., ser2net://..)')
        add('--baudrate', type=int, default=9600, help='baud rate')
        add('--bytesize', type=int, choices=[6, 7, 8],
            default=serial.EIGHTBITS, help='byte size')
        add('--parity', choices=serial.PARITY_NAMES.keys(),
            default=serial.PARITY_NONE, help='parity type')
        add('--timeout', type=float, default=5, help='timeout')
        add('--stopbits', type=float, choices=[1, 1.5, 2],
            default=serial.STOPBITS_ONE, help='stop bits')
        add('--xonxoff', action='store_true', default=False, help='')
        add('--rtscts', action='store_true', default=False, help='')
        add('--write-timeout', dest='writeTimeout', type=float, default=None,
            help='')
        add('--dsrdtr', action='store_true', default=False, help='')
        add('--interchar-timeout', dest='interCharTimeout', type=float,
            default=None, help='')
        add('--eol', type=str, default='\n',
            help="end of line [default: '\\n']")

    args = parser.parse_args()
    vargs = vars(args)

    log_level = vargs.pop('log_level').upper()
    scpi_log_level = vargs.pop('scpi_log_level').upper()
    logging.basicConfig(level=log_level,
                        format="%(asctime)s %(levelname)s %(name)s: %(message)s")
    gevent_arg = vargs.pop('gevent')

    conn = vargs.pop('connection')
    kwargs = { conn: vargs, 'commands': COMMANDS }
    mode = not gevent_arg and "interactive, no gevent" or "gevent"
    scpi = SCPI(**kwargs)
    scpi._logger.setLevel(scpi_log_level)
    local = dict(s=scpi)
    banner = "\nWelcome to SCPI console " \
             "(connected to {0}) ({1})\n".format(scpi, mode)

    sys.ps1 = "scpi> "
    sys.ps2 = len(sys.ps1)*"."

    if gevent_arg:
        try:
            from gevent.monkey import patch_sys
        except ImportError:
            mode = "no gevent"
        else:
            patch_sys()

    import code
    code.interact(banner=banner, local=local)
Ejemplo n.º 13
0
def main(argv=None):
    """
    Start a SCPI console

    The following example will start a SCPI console with one SCPI instrument
    called *s*::

        $ python -m Salsa.core.communications.scpi gpib --pad=15 enet://gpibhost

        scpi> print s['*IDN']
    """

    import sys
    import argparse

    try:
        import serial
    except:
        serial = None

    parser = argparse.ArgumentParser(description=main.__doc__)

    parser.add_argument('--log-level', type=str, default='info',
                        choices=['trace', 'debug', 'info', 'warning', 'error'],
                        help='global log level [default: info]')
    parser.add_argument('--scpi-log-level', type=str, default='info',
                        choices=['trace', 'debug', 'info', 'warning', 'error'],
                        help='log level for scpi object[default: info]')
    parser.add_argument('--gevent', action='store_true', default=False,
                        help='enable gevent in console [default: False]')

    subparsers = parser.add_subparsers(title="connection", dest="connection",
                                       description="valid type of connections",
                                       help="choose one type of connection")

    gpib_parser = subparsers.add_parser('gpib', help='GPIB connection')
    add = gpib_parser.add_argument
    add('url', type=str,
        help='gpib instrument url (ex: gpibhost, enet://gpibhost:5000)')
    add('--pad', type=int, required=True, help='primary address')
    add('--sad', type=int, default=0, help='secondary address [default: 0]')
    add('--tmo', type=int, default=10,
        help='gpib timeout (gpib tmo unit) [default: 10 (=300ms)]')
    add('--eos', type=str, default='\n', help=r"end of string [default: '\n']")
    add('--timeout', type=float, default=0.4,
        help='socket timeout [default: 0.4]')

    tcp_parser = subparsers.add_parser('tcp', help='TCP connection')
    add = tcp_parser.add_argument
    add('url', type=str,
        help='tcp instrument url (ex: host:5000, socket://host:5000)')
    add('--port', required=True, type=int, help='port')
    add('--timeout', type=float, default=5, help='timeout')
    add('--eol', type=str, default='\n',
        help=r"end of line [default: '\n']")

    if serial:
        serial_parser = subparsers.add_parser('serial',
                                              help='serial line connection')
        add = serial_parser.add_argument
        add('port', type=str,
            help='serial instrument port (ex: rfc2217://.., ser2net://..)')
        add('--baudrate', type=int, default=9600, help='baud rate')
        add('--bytesize', type=int, choices=[6, 7, 8],
            default=serial.EIGHTBITS, help='byte size')
        add('--parity', choices=serial.PARITY_NAMES.keys(),
            default=serial.PARITY_NONE, help='parity type')
        add('--timeout', type=float, default=5, help='timeout')
        add('--stopbits', type=float, choices=[1, 1.5, 2],
            default=serial.STOPBITS_ONE, help='stop bits')
        add('--xonxoff', action='store_true', default=False, help='')
        add('--rtscts', action='store_true', default=False, help='')
        add('--write-timeout', dest='writeTimeout', type=float, default=None,
            help='')
        add('--dsrdtr', action='store_true', default=False, help='')
        add('--interchar-timeout', dest='interCharTimeout', type=float,
            default=None, help='')
        add('--eol', type=str, default='\n',
            help="end of line [default: '\\n']")

    args = parser.parse_args()
    vargs = vars(args)

    log_level = vargs.pop('log_level').upper()
    scpi_log_level = vargs.pop('scpi_log_level').upper()
    logging.basicConfig(level=log_level,
                        format="%(asctime)s %(levelname)s %(name)s: %(message)s")
    gevent_arg = vargs.pop('gevent')

    conn = vargs.pop('connection')
    kwargs = { conn: vargs }
    mode = not gevent_arg and "interactive, no gevent" or "gevent"
    scpi = Scpi(**kwargs)
    scpi._logger.setLevel(scpi_log_level)
    local = dict(s=scpi)
    banner = "\nWelcome to SCPI console " \
             "(connected to {0}) ({1})\n".format(scpi, mode)

    sys.ps1 = "scpi> "
    sys.ps2 = len(sys.ps1)*"."

    if gevent_arg:
        try:
            from gevent.monkey import patch_sys
        except ImportError:
            mode = "no gevent"
        else:
            patch_sys()

    import code
    code.interact(banner=banner, local=local)
Ejemplo n.º 14
0
def main():
    """
    Start a Keithley console.

    The following example will start a Keithley console with one Keithley
    instrument called *k*::

        $ python -m bliss.controllers.keithley gpib --pad=15 enet://gpibhost

        keithley> print( k['*IDN?'] )

     """

    import sys
    import logging
    import argparse

    try:
        import serial
    except:
        serial = None

    parser = argparse.ArgumentParser(description=main.__doc__)
    parser.add_argument(
        '--model',
        type=str,
        default=None,
        help='keithley model (ex: 6482) [default: auto discover]')
    parser.add_argument('--log-level',
                        type=str,
                        default='info',
                        choices=['debug', 'info', 'warning', 'error'],
                        help='log level [default: info]')
    parser.add_argument('--scpi-log-level',
                        type=str,
                        default='info',
                        choices=['trace', 'debug', 'info', 'warning', 'error'],
                        help='log level for scpi object [default: info]')
    parser.add_argument('--keithley-log-level',
                        type=str,
                        default='info',
                        choices=['trace', 'debug', 'info', 'warning', 'error'],
                        help='log level for keithley object [default: info]')
    parser.add_argument('--gevent',
                        action='store_true',
                        default=False,
                        help='enable gevent in console [default: False]')

    subparsers = parser.add_subparsers(
        title='object/connection',
        dest='connection',
        description='config object name or valid type of connections',
        help='choose keithley config object name or type of connection')
    config_parser = subparsers.add_parser('config',
                                          help='keithey config object')
    config_parser.add_argument('name', help='config object name')

    gpib_parser = subparsers.add_parser('gpib', help='GPIB connection')
    add = gpib_parser.add_argument
    add('url',
        type=str,
        help='gpib instrument url (ex: gpibhost, enet://gpibhost:5000)')
    add('--pad', type=int, required=True, help='primary address')
    add('--sad', type=int, default=0, help='secondary address [default: 0]')
    add('--tmo',
        type=int,
        default=10,
        help='GPIB timeout (GPIB tmo unit) [default: 11 (=1s)]')
    add('--eos', type=str, default='\n', help=r"end of string [default: '\n']")
    add('--timeout',
        type=float,
        default=1.1,
        help='socket timeout [default: 1.1]')

    tcp_parser = subparsers.add_parser('tcp', help='TCP connection')
    add = tcp_parser.add_argument
    add('url', type=str, help='TCP instrument url (ex: keith6485:25000)')

    if serial:
        serial_parser = subparsers.add_parser('serial',
                                              help='serial line connection')
        add = serial_parser.add_argument
        add('port',
            type=str,
            help='serial instrument port (ex: rfc2217://.., ser2net://..)')
        add('--baudrate', type=int, default=9600, help='baud rate')
        add('--bytesize',
            type=int,
            choices=[6, 7, 8],
            default=serial.EIGHTBITS,
            help='byte size')
        add('--parity',
            choices=serial.PARITY_NAMES.keys(),
            default=serial.PARITY_NONE,
            help='parity type')
        add('--timeout', type=float, default=5, help='timeout')
        add('--stopbits',
            type=float,
            choices=[1, 1.5, 2],
            default=serial.STOPBITS_ONE,
            help='stop bits')
        add('--xonxoff', action='store_true', default=False, help='')
        add('--rtscts', action='store_true', default=False, help='')
        add('--write-timeout',
            dest='writeTimeout',
            type=float,
            default=None,
            help='')
        add('--dsrdtr', action='store_true', default=False, help='')
        add('--interchar-timeout',
            dest='interCharTimeout',
            type=float,
            default=None,
            help='')
        add('--eol',
            type=str,
            default='\n',
            help="end of line [default: '\\n']")

    args = parser.parse_args()
    vargs = vars(args)

    model = vargs.pop('model', None)
    log_level = getattr(logging, vargs.pop('log_level').upper())
    keithley_log_level = vargs.pop('keithley_log_level').upper()
    scpi_log_level = vargs.pop('scpi_log_level').upper()
    logging.basicConfig(
        level=log_level,
        format='%(asctime)s %(levelname)s %(name)s: %(message)s')
    gevent_arg = vargs.pop('gevent')

    conn = vargs.pop('connection')
    local = {}
    if conn == 'config':
        from bliss.config.static import get_config
        config = get_config()
        name = vargs['name']
        keithley = create_objects_from_config_node(
            config, config.get_config(name))[name]
        if isinstance(keithley, Sensor):
            sensor = keithley
            keithley = sensor.controller
            local['s'] = sensor
    else:
        kwargs = {conn: vargs, 'model': model}
        keithley = KeithleySCPI(**kwargs)
    local['k'] = keithley
    keithley._logger.setLevel(keithley_log_level)
    keithley.language._logger.setLevel(scpi_log_level)
    keithley.interface._logger.setLevel(scpi_log_level)

    sys.ps1 = 'keithley> '
    sys.ps2 = len(sys.ps1) * '.'

    if gevent_arg:
        try:
            from gevent.monkey import patch_sys
        except ImportError:
            mode = 'no gevent'
        else:
            patch_sys()

    import code
    mode = not gevent_arg and 'interactive, no gevent' or 'gevent'
    banner = '\nWelcome to Keithley console ' \
             '(connected to {0}) ({1})\n'.format(keithley, mode)
    code.interact(banner=banner, local=local)
Ejemplo n.º 15
0
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
#
from gevent import monkey; monkey.patch_sys(stdin=False, stdout=True, stderr=False)
from wishbone import Actor
from os import getpid
from colorama import init, Fore, Back, Style
import sys
from wishbone.event import Bulk


class Format():

    def __init__(self, selection, counter, pid):
        self.selection = selection
        if counter:
            self.counter = self.__returnCounter
        else:
            self.counter = self.__returnNoCounter