Esempio n. 1
0
 def __init__(
     self,
     CALLBACK=None,
     BUF_SIZE=1,
     FILTER={'data'},
     WAIT_TIME=0.1,
     loop: asyncio.AbstractEventLoop() = None,
     executor: futures.Executor() = None,
     step_time=0.01,
     returnNone=False,
     count=0
     # Partially Timeout time stamps will be discarded on False
     # None will be returned for timeout data on True.
 ):
     self.WAIT_TIME = WAIT_TIME
     self.FILTER = FILTER
     self.BUF_SIZE = BUF_SIZE
     self.step_time = step_time
     self.buf_time_out = self.BUF_SIZE * self.WAIT_TIME * 2
     self._input_list = []
     self._output_list = []
     self._input_queue = asyncio.Queue()
     if loop:
         self.loop = loop
     else:
         self.loop = asyncio.get_event_loop()
     self.executor = executor
     if CALLBACK:
         self.CALLBACK = CALLBACK
     self.returnNone = returnNone
     self.count = count
Esempio n. 2
0
 def __init__(
     self,
     REMOTE_IP,
     REMOTE_PORT,
     loop: asyncio.AbstractEventLoop() = None,
     executor: futures.Executor() = None
 ):
     self._input_list = []
     self._input_queue = asyncio.Queue()
     if loop:
         self.loop = loop
     else:
         self.loop = asyncio.get_event_loop()
     self.executor = executor
     self.REMOTE_IP = REMOTE_IP
     self.REMOTE_PORT = REMOTE_PORT
Esempio n. 3
0
    def __init__(self,
                 SERVER_IP='10.0.0.1',
                 SERVER_TCP_PORT=4712,
                 CLIENT_TCP_PORT='AUTO',
                 SERVER_UDP_PORT=4713,
                 CLIENT_UDP_PORT='AUTO',
                 MODE='TCP',
                 IDCODE=1,
                 loop: asyncio.AbstractEventLoop() = None,
                 executor: futures.Executor() = None,
                 parser: Parser() = None,
                 count=0):
        self.IDCODE = IDCODE
        self.SERVER_IP = SERVER_IP
        self.SERVER_TCP_PORT = SERVER_TCP_PORT
        self.CLIENT_TCP_PORT = CLIENT_TCP_PORT
        self.SERVER_UDP_PORT = SERVER_UDP_PORT
        self.CLIENT_UDP_PORT = CLIENT_UDP_PORT
        self.MODE = MODE
        self.executor = executor
        if loop:
            self.loop = loop
        else:
            self.loop = asyncio.get_event_loop()
        if parser:
            self.parser = parser
        else:
            self.parser = Parser()
        self._output_list = []
        self.count = count
        if self.MODE == 'TCP':

            async def connect():
                self._count = count
                print('Connecting to:', self.SERVER_IP, '...')
                await self.loop.create_connection(lambda: self._TCP(self),
                                                  host=self.SERVER_IP,
                                                  port=self.SERVER_TCP_PORT)

            async def close():
                if self.cmd_transport:
                    self.cmd_transport.close()

        self.connect = connect
        self.close = close
Esempio n. 4
0
 def __init__(
     self,
     device_list=[],
     connection_list=[],
     loop: asyncio.AbstractEventLoop() = None,
     executor: futures.Executor() = None
 ):
     if loop:
         self.loop = loop
     else:
         self.loop = asyncio.get_event_loop()
     if executor:
         self.executor = executor
     else:
         self.executor = futures.ProcessPoolExecutor()
     self.loop.set_default_executor(self.executor)
     self.device_list = device_list
     self.connection_list = connection_list
Esempio n. 5
0
@author: sch
"""
import sys
import asyncio

__doc__ = "异步策略测试"

# -----------------------------------默认异步策略-----------------------------------------
loop_policy = asyncio.get_event_loop_policy()
print("loop_policy -> ", loop_policy)

# -----------------------------------不同的异步策略----------------------------------------
select_loop = asyncio.SelectorEventLoop()
print("select_loop - > ", select_loop)

abstract_loop = asyncio.AbstractEventLoop()
print("abstract_loop - > ", abstract_loop)

if sys.platform == 'win32':
    proactor_loop = asyncio.ProactorEventLoop()
    print("proactor_loop -> ", proactor_loop)

# 更改异步策略
loop = asyncio.get_event_loop()
print("loop -> ", loop)

asyncio.set_event_loop(abstract_loop)
print(asyncio.get_event_loop())

asyncio.new_event_loop()
print(asyncio.get_event_loop())