本文整理汇总了Python中socketIO_client.SocketIO._close方法的典型用法代码示例。如果您正苦于以下问题:Python SocketIO._close方法的具体用法?Python SocketIO._close怎么用?Python SocketIO._close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socketIO_client.SocketIO
的用法示例。
在下文中一共展示了SocketIO._close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KeyboardReader
# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import _close [as 别名]
class KeyboardReader(object):
def __init__(self, args):
self.args = args
self.device = None
self.ws = None
signal.signal(signal.SIGTERM, self.__stop_app)
signal.signal(signal.SIGINT, self.__stop_app)
self.ws = SocketIO(args.hostname, args.port)
if args.all_devices:
self.read_all_keyboards()
else:
if args.device_filename:
self.device_filename = args.device_filename
else:
self.device_filename = self.load_device_filename()
self.read_keyboard()
def connect_keyboard(self):
while True:
try:
if not self.args.silent:
print('Openning device {}...'.format(self.device_filename))
self.device = evdev.InputDevice(self.device_filename)
break
except OSError:
if not self.args.silent:
print('Can\'t open device. Waiting...')
time.sleep(1)
xinput.disable_device(self.device_filename)
if not self.args.silent:
print('Success!'.format(self.device_filename))
def __stop_app(self, signum, frame):
print('Trap called, exiting...')
if self.device:
self.device.close()
if self.ws:
self.ws._close()
xinput.trap_handler(signum, frame)
sys.exit(0)
def get_all_devices(self):
keyboards = os.popen('readlink -f /dev/input/by-path/*kbd').read().split('\n')
open_devices = []
for keyboard in keyboards:
if not keyboard:
continue
try:
device = evdev.InputDevice(keyboard)
except OSError:
continue
try:
open_device = evdev.InputDevice(device.fn)
except OSError:
continue
open_devices.append(open_device)
return open_devices
def send_ws_keyboard_list(self, open_devices):
keyboard_package = [
{
'file': keyboard.fn,
'name': keyboard.name
}
for keyboard in open_devices
]
if not self.args.silent:
print(keyboard_package)
self.ws.emit('devices_list', {
'devices': keyboard_package
})
def read_all_keyboards(self):
open_devices = self.get_all_devices()
last_time = 0
while True:
if time.time() > last_time + 5:
open_devices = self.get_all_devices()
self.send_ws_keyboard_list(open_devices)
last_time = time.time()
for num, device in enumerate(open_devices):
try:
event = device.read_one()
#.........这里部分代码省略.........
示例2: WaptTestHost
# 需要导入模块: from socketIO_client import SocketIO [as 别名]
# 或者: from socketIO_client.SocketIO import _close [as 别名]
class WaptTestHost(object):
def __init__(self,config_filename = 'c:/wapt/wapt-get.ini'):
self.config_filename = config_filename
self.config = WaptServiceConfig(config_filename)
self.socketio_client = None
self.wapt_remote_calls = None
def run(self):
self.config.reload_if_updated()
with Wapt(config_filename = self.config.config_filename) as tmp_wapt:
logger.info('Starting socketio on "%s://%s:%s" ...' % (self.config.websockets_proto,self.config.websockets_host,self.config.websockets_port))
logger.debug('Certificate checking : %s' % self.config.websockets_verify_cert)
while True:
try:
if not self.socketio_client and self.config.websockets_host:
logger.debug('Creating socketio client')
logger.debug('Proxies : %s'%self.config.waptserver.proxies)
# bug in socketio... ? we must not pass proxies at all (even None) if we don"t want to switch to polling mode...
kwargs = {}
if self.config.waptserver.proxies and self.config.waptserver.proxies.get(self.config.websockets_proto,None) is not None:
kwargs['proxies'] = self.config.waptserver.proxies
if not self.socketio_client:
self.socketio_client = SocketIO(
host="%s://%s" % (self.config.websockets_proto,self.config.websockets_host),
port=self.config.websockets_port,
Namespace = WaptSocketIORemoteCalls,
verify=self.config.websockets_verify_cert,
wait_for_connection = False,
transport = ['websocket'],
ping_interval = self.config.websockets_ping,
hurry_interval_in_seconds = self.config.websockets_hurry_interval,
params = {'uuid': tmp_wapt.host_uuid,'login':self.config.websockets_auth},
**kwargs)
#self.socketio_client.get_namespace().wapt = tmp_wapt
if self.socketio_client and self.config.websockets_host:
if not self.socketio_client.connected:
self.socketio_client._http_session.params.update({'uuid': tmp_wapt.host_uuid,'login':self.config.websockets_auth})
self.socketio_client.define(WaptSocketIORemoteCalls)
#self.socketio_client.get_namespace().wapt = tmp_wapt
self.socketio_client.connect('')
if self.socketio_client.connected:
logger.info('Socket IO listening for %ss' % self.config.websockets_check_config_interval )
self.socketio_client.wait(self.config.websockets_check_config_interval)
self.config.reload_if_updated()
except Exception as e:
print('Error in socket io connection %s' % repr(e))
self.config.reload_if_updated()
if self.socketio_client:
print('stop sio client')
self.socketio_client._close()
del self.socketio_client
self.socketio_client = None
if self.socketio_client and self.config.websockets_host:
self.socketio_client._http_session.params.update({'uuid': tmp_wapt.host_uuid,'login':self.config.websockets_auth})
logger.info('Socket IO Stopped, waiting %ss before retrying' % self.config.websockets_retry_delay)
time.sleep(self.config.websockets_retry_delay)