Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def flush_loop(queue, encoding):
try:
stdout_write=sys.stdout.write
stdout_flush=sys.stdout.flush
if type(sys.stdout) is not file:
stdout_write=rpyc.async(sys.stdout.write)
stdout_flush=rpyc.async(sys.stdout.flush)
while True:
buf=b""
while True:
try:
buf+=queue.get_nowait()
except Empty:
break
if buf:
if encoding:
try:
buf=buf.decode(encoding)
except Exception:
pass
stdout_write(buf)
stdout_flush()
def ReduceBy(self, key_extractor, reduce_function):
# make async objects
anetrefs = [rpyc.async(dia.ReduceBy) for dia in self._dias]
# issue async requests
_key_extractor = marshal.dumps(key_extractor.__code__)
_reduce_function = marshal.dumps(reduce_function.__code__)
asyncs = [ref(_key_extractor, _reduce_function) for ref in anetrefs]
for a in asyncs:
a.wait()
# return RemoteDIA
return RemoteDIA([a.value for a in asyncs])
def AllGather(self):
# make async objects
anetrefs = [rpyc.async(dia.AllGather) for dia in self._dias]
# issue async requests
asyncs = [ref() for ref in anetrefs]
for a in asyncs:
a.wait()
# return values of workers as list
return [a.value for a in asyncs]
def ssh_interactive(term, w, h, wp, hp, host, port, user, passwords, private_keys, program, data_cb, close_cb):
private_keys = obtain(private_keys)
passwords = obtain(passwords)
data_cb = async(data_cb)
close_cb = async(close_cb)
ssh_passwords, key_passwords = passwords
try:
ssh = SSH(host, port, user, ssh_passwords, key_passwords, private_keys, interactive=True)
if not ssh.connected:
raise ValueError('No valid credentials found to connect to {}:{} user={}'.format(
ssh.host, ssh.port, ssh.user or 'any'))
except gaierror as e:
raise ValueError('Unable to connect to {}:{} - {}'.format(host, port, e.strerror))
except NoValidConnectionsError:
raise ValueError('Unable to connect to {}:{}'.format(host, port))
def _sendData(target_clientID, sender, data, datatype, tabTarget):
'''
Send data the to target client, could be message, otl or settings.
'''
global server_conn
if not server_conn:
print("ERROR: Client is not connected.")
return False
try:
setDataAsync = rpyc.async(server_conn.root.sendDataToClient)
result = setDataAsync(target_clientID, datatype, sender, data, tabTarget)
return result
except AttributeError:
return False
print("ERROR: client " + target_clientID + " not found.")
self.pupyimporter = self.conn.pupyimporter
if self.conn.register_remote_cleanup:
register_package_request_hook = rpyc.async(self.pupyimporter.register_package_request_hook)
register_package_error_hook = rpyc.async(self.pupyimporter.register_package_error_hook)
self.conn.register_remote_cleanup(self.pupyimporter.unregister_package_request_hook)
register_package_request_hook(self.remote_load_package)
self.conn.register_remote_cleanup(self.pupyimporter.unregister_package_error_hook)
register_package_error_hook(self.remote_print_error)
self.pupy_load_dll = getattr(self.pupyimporter, 'load_dll', None)
self.new_dlls = getattr(self.pupyimporter, 'new_dlls', None)
self.new_modules = getattr(self.pupyimporter, 'new_modules', None)
self.remote_add_package = rpyc.async(self.pupyimporter.pupy_add_package)
self.remote_invalidate_package = rpyc.async(self.pupyimporter.invalidate_module)
if self.conn.obtain_call:
def obtain_call(function, *args, **kwargs):
if args or kwargs:
packed_args = msgpack.dumps((args, kwargs))
packed_args = zlib.compress(packed_args)
else:
packed_args = None
result = self.conn.obtain_call(function, packed_args)
result = zlib.decompress(result)
result = msgpack.loads(result)
return result
def register_package_error_hook(hook):
global remote_print_error
import rpyc
remote_print_error = rpyc.async(hook)
if self.conn.register_remote_cleanup:
register_package_request_hook = rpyc.async(self.pupyimporter.register_package_request_hook)
register_package_error_hook = rpyc.async(self.pupyimporter.register_package_error_hook)
self.conn.register_remote_cleanup(self.pupyimporter.unregister_package_request_hook)
register_package_request_hook(self.remote_load_package)
self.conn.register_remote_cleanup(self.pupyimporter.unregister_package_error_hook)
register_package_error_hook(self.remote_print_error)
self.pupy_load_dll = getattr(self.pupyimporter, 'load_dll', None)
self.new_dlls = getattr(self.pupyimporter, 'new_dlls', None)
self.new_modules = getattr(self.pupyimporter, 'new_modules', None)
self.remote_add_package = rpyc.async(self.pupyimporter.pupy_add_package)
self.remote_invalidate_package = rpyc.async(self.pupyimporter.invalidate_module)
if self.conn.obtain_call:
def obtain_call(function, *args, **kwargs):
if args or kwargs:
packed_args = msgpack.dumps((args, kwargs))
packed_args = zlib.compress(packed_args)
else:
packed_args = None
result = self.conn.obtain_call(function, packed_args)
result = zlib.decompress(result)
result = msgpack.loads(result)
return result
self.obtain_call = obtain_call
def __init__(self, ref):
self.create_connection = ref['create_connection']
self.connect = rpyc.async(ref['connect'])
self.on_connected = rpyc.async(ref['on_connected'])
self.on_data = rpyc.async(ref['on_data'])
self.on_disconnect = rpyc.async(ref['on_disconnect'])