Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def init(self):
"""initialize the plugin."""
opt = dotdict(id=self.pid, secret=self.secret)
self.conn = PluginConnection(self, opt)
self.conn.setup()
self.terminated = False
initialized = self.loop.create_future()
self.on_plugin_message("initialized", initialized)
self.on_plugin_message("disconnected", self.terminate)
await initialized
workers = [
self.message_worker(self.janus_queue.async_q, self.conn.abort)
for i in range(2)
]
asyncio.ensure_future(asyncio.gather(*workers))
async def init(self):
"""initialize the plugin."""
opt = dotdict(id=self.pid, secret=self.secret)
self.conn = PluginConnection(opt, client=self)
self.terminated = False
initialized = self.loop.create_future()
self.on_plugin_message("initialized", initialized)
self.on_plugin_message("disconnected", self.terminate)
await initialized
workers = [
self.message_worker(self.janus_queue.async_q, self.conn.abort)
for i in range(2)
]
asyncio.ensure_future(asyncio.gather(*workers))
job = await async_q.get()
async_q.task_done()
if job is None:
continue
if "setInterface" == job["type"]:
api = self.conn.set_remote(job["api"])
self.conn.local["np"] = np
self.conn.emit({"type": "interfaceSetAsRemote"})
if not self.conn.init:
self.conn.set_interface(self.imjoy_api)
self.conn.init = True
async_q.task_done()
else:
handler = JOB_HANDLERS_PY3.get(job["type"])
if handler is None:
continue
try:
await handler(self.conn, job, logger)
except Exception: # pylint: disable=broad-except
logger.error(
"Error occured in the loop %s", traceback.format_exc()
)
finally:
sys.stdout.flush()
except Exception as e:
print(e)
job = await async_q.get()
async_q.task_done()
if job is None:
continue
if "setInterface" == job["type"]:
api = self.conn.set_remote(job["api"])
self.conn.local["np"] = np
self.conn.emit({"type": "interfaceSetAsRemote"})
if not self.conn.init:
self.conn.set_interface(self.imjoy_api)
self.conn.init = True
async_q.task_done()
else:
handler = JOB_HANDLERS_PY3.get(job["type"])
if handler is None:
continue
try:
await handler(self.conn, job, logger)
except Exception: # pylint: disable=broad-except
logger.error(
"Error occured in the loop %s", traceback.format_exc()
)
finally:
sys.stdout.flush()
except Exception as e:
print(e)
async def init(self):
"""initialize the plugin."""
opt = dotdict(id=self.pid, secret=self.secret)
self.conn = PluginConnection(self, opt)
self.conn.setup()
self.terminated = False
initialized = self.loop.create_future()
self.on_plugin_message("initialized", initialized)
self.on_plugin_message("disconnected", self.terminate)
await initialized
workers = [
self.message_worker(self.janus_queue.async_q, self.conn.abort)
for i in range(2)
]
asyncio.ensure_future(asyncio.gather(*workers))
async def init(self):
"""initialize the plugin."""
opt = dotdict(id=self.pid, secret=self.secret)
self.conn = PluginConnection(opt, client=self)
self.terminated = False
initialized = self.loop.create_future()
self.on_plugin_message("initialized", initialized)
self.on_plugin_message("disconnected", self.terminate)
await initialized
workers = [
self.message_worker(self.janus_queue.async_q, self.conn.abort)
for i in range(2)
]
asyncio.ensure_future(asyncio.gather(*workers))
def run(self):
try:
while not self._halt.is_set():
try:
self._send_heartbeat()
except TimeoutError:
pass
if self._adrenaline.is_set():
interval_in_seconds = self._hurry_interval_in_seconds
else:
interval_in_seconds = self._relax_interval_in_seconds
self._rest.wait(interval_in_seconds)
except ConnectionError:
logging.debug("[heartbeat connection error]")
def emit(self, event, *args, **kw):
socketIO_packet_type = 2
path = kw.get("path", "")
callback, args = find_callback(args, kw)
ack_id = self._set_ack_callback(callback) if callback else None
args = [event] + list(args)
socketIO_packet_data, binary_packets = format_socketIO_packet_data(
path, ack_id, args
)
if binary_packets:
socketIO_packet_type += 3
self._message(str(socketIO_packet_type) + socketIO_packet_data)
for packet in binary_packets:
self._message(packet)
def __init__(self, client, opt):
"""Set up connection instance."""
self.secret = opt.secret
self.id = opt.id # pylint: disable=invalid-name
self.local = {}
self._remote = dotdict()
self.interface = {}
self.plugin_interfaces = {}
self.remote_set = False
self.store = ReferenceStore()
self.executed = False
self.init = False
self.abort = threading.Event()
self.work_dir = opt.work_dir
self.opt = opt
self._registered_plugins[self.id] = self
self.client = client
def emit(_):
raise NotImplementedError
self.emit = emit
resolve.__jailed_pairs__ = reject
reject.__jailed_pairs__ = resolve
self.emit(
{
"type": "callback",
"id": id_,
"num": arg_num,
# 'pid' : self.id,
"args": self._wrap(arguments),
"promise": self._wrap([resolve, reject]),
}
)
if PYTHON3:
return FuturePromise(pfunc, self.client.loop)
return Promise(pfunc)