Erlang Shell Tunnel - erlang

Is it possible to create a shell tunnel, connect to it from outside, and send commands to it?
I want to manage nodes and send arbitrary commands from outside of Erlang without creating an API.
erlshell = Erlshell(host="localhost")
res = erlshell.exec("""
A = 2,
B = 5,
A + B
")
print(res)
I found this project (http://erlport.org/) but it hasn't had activity in 6 years.

Related

Is any way to start go_binary before java_test?

Our project has a few GRPC servers defined as go_binary targets. We develop client SDKs for Java and Python applications and we would like to use java_test and py_test. Is any way to start a specific go_binary target before java_test or py_test?
You can create a test harness that starts the gRPC server before running the tests. For example, you could add the binary to the data attribute of the test, and then started it beforehand:
go_binary(
name = "my_grpc_server",
[...]
)
py_test(
name = "my_test",
[...]
data = [":my_grpc_server"],
)
and then inside the test file:
class ClientTestCase(unittest.TestCase):
def setUp(self):
r = runfiles.Create()
self.server = subprocess.Popen([r.Rlocation("path/to/my_grpc_server")])
def tearDown(self):
self.server.terminate()
self.server.wait()
This example is very simple, you'll probably run into issues regarding the availability of the port the server listens on, or waiting for the server to start up. You could add flags to your gRPC server to allow communication over a domain socket, or make it listen on an unused port and have the test parse the port number from the server's log output.
For details on finding the server with runfiles: https://github.com/bazelbuild/bazel/blob/a7a0d48fbeb059ee60e77580e5d05baeefdd5699/tools/python/runfiles/runfiles.py#L16-L58
If you find yourself copy-pasting this pattern a lot, or having to implement it in multiple languages, you could try using an sh_test() rule to wrap the underlying py_test or java_test, and to start the server, then start the test with an environment variable telling it how to reach the server (eg MY_GRPC_SERVER_ADDRESS=localhost:${test_port}.

TFF: Remote Executor

We are setting up a federated scenario with Server and Client on different physical machines.
On the server, we have used the docker container to kickstart:
The above has been borrowed from Kubernetes tutorial. We believe this creates a 'local executor' [Ref 1] which helps create a gRPC server [Ref 2].
Ref 1:
Ref 2:
Next on the client 1, we are calling tff.framework.RemoteExecutor that connects to the gRPC server.
Our understanding based on the above is that the Remote Executor runs on the client which connects to the gRPC server.
Assuming the above is correct, how can we send a
tff.tf_computation
from the server to the client and print the output on the client side to ensure the whole setup works well.
Your understanding is definitely correct.
If you construct an ExecutorFactory directly, as seems to be the case in the code above, passing it to tff.framework.set_default_context will install your remote stack as the default mechanism for executing computations in the TFF runtime. You should additionally be able to pass the appropriate channels to tff.backends.native.set_remote_execution_context to handle the remote executor construction and context installation if desired, but the way you are doing it certainly works, and allows for greater customization.
Once you have set this up, running an example end-to-end should be fairly simple. We will set up a computation which takes a set of federated integers, prints on the clients, and sums the integers up. Let:
#tff.tf_computation(tf.int32)
def print_and_return(x):
# We must use tf.print here, as this logic will be
# serialized and run on the clients as TensorFlow.
tf.print('hello world')
return x
#tff.federated_computation(tff.FederatedType(tf.int32, tff.CLIENTS))
def print_and_sum(federated_arg):
same_ints = tff.federated_map(print_and_return, federated_arg)
return tff.federated_sum(same_ints)
Suppose we have N clients; we simply instantiate the set of federated integers, and invoke our computation.
federated_ints = [1] * N
total = print_and_sum(federated_ints)
assert total == N
This should cause the tf.prints defined above to run on the remote machine; as long as tf.print is directed to an output stream which you can monitor, you should be able to see it.
PS: you may note that the federated sum above is unnecessary; it certainly is. The same effect can be had by simply mapping the identity function with the serialized print.

Dask with tls connection can not end the program with to_parquet method

I am using dask to process 10 files which the size of each file is about 142MB. I build a method with delayed tag, following is an example:
#dask.delayed
def process_one_file(input_file_path, save_path):
res = []
for line in open(input_file_path):
res.append(line)
df = pd.DataFrame(line)
df.to_parquet(save_path+os.path.basename(input_file_path))
if __name__ == '__main__':
client = ClusterClient()
input_dir = ""
save_dir = ""
print("start to process")
cvss = [process_one_file(input_dir+filename, save_dir) for filename in os.listdir(input_dir)]
dask.compute(csvs)
However, dask does not always run successfully. After processing all files, the program often hangs.
I used the command line to run the program. The program often huangs after printing start to process. I know the program runs correctly, since I can see all output files after a while.
But the program never stops. If I disabled tls, the program can run successfully.
It was so strange that dask can not stop the program if I enable tls connection. How can I solve it?
I found that if I add to_parquet method, then the program cannot stop, while if I remove the method, it runs successfully.
I have found the problem. I set 10GB for each process. That means I set memory-limit=10GB. I totally set 2 workers and each has 2 processes. Each process has 2 threads.
Thus, each machine will have 4 processes which occupy 40GB. However, my machine only have 32GB. If I lower the memory limit, then the program will run successfully!

How can I kill a child process using LUA?

I'm trying to kill a process using Lua: my bash script "run.sh" prints a string each 2 seconds and up to now I was able to catch real-time the output but I need to quit that process too whenever i send a command to my telegram bot
Here is my actual code:
local bot, extension = require("lua-bot-api").configure('myBotToken')
local function test()
local pipe = io.popen'/home/ubuntu/workspace/LmBot/run.sh'
repeat
local c = pipe:read("*line")
if c then
io.write(c)
io.flush()
bot.sendMessage(msg.from.id,c,"Markdown")
end
until not c
pipe:close()
end
extension.onTextReceive = function(msg)
local matches = {msg.text:match('^/(.+)$')}
if(matches[1]=='start')then
test()
end
end
extension.run()
As you can see, when I send command /start it runs my bash script (is that a child process? am I right?) and sends me back a message with the output parsed by lines in real time.
I now need to be able to kill the process started before, are there any ways using lua?
Thank you all in advance :)

VBS script fails to run when called as a Scheduled Task in Windows 8

I have created a VBS script that runs perfectly fine when manually run on Windows 8 Home computers even on IDs that have no admin rights. This same script fails repeatedly no matter what user credentials I've used to run it through a scheduled task on computer start up. I've tried the system, admin, and unprivileged user IDs that are on the machine all with no success.
This same VBS script has no issues at all being run from a scheduled task on multiple Windows 7, and Windows 8.1 Home and Professional machines.
This script attempts to successfully ping a website, and upon successful ping will POST data to the web page with the current time of the local computer.
boolExitFlag = False
Do
If Ping("HOSTNAME") Then
Call pingsuccess
boolExitFlag = True
End If
WScript.sleep 1000
Loop while boolExitFlag <> True
Sub pingsuccess
set oHTTP = CreateObject("Microsoft.XMLHTTP")
oHTTP.open "POST", "URL",false
oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHTTP.setRequestHeader "Content-Length", Len("send=send&time=" & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now))
oHTTP.send "send=send&time=" & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)
End Sub
Function Ping(strHost)
Dim oPing, oRetStatus, bReturn
Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address='" & strHost & "'")
For Each oRetStatus In oPing
If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
bReturn = False
Else
bReturn = True
End If
Set oRetStatus = Nothing
Next
Set oPing = Nothing
Ping = bReturn
End Function
When the scheduled task is run on the Windows 8 machines I see
"The task is currently running. (0x41301)" with no success. I have tried nearly EVERYTHING to attempt to get this working outside of writing a batch script to run the VBS script. That just seems excessively unnecessary though.
The only way that I could manage to get Windows 8 to run this VBS script was to create a batch file that called the VBS, and checked the box in the scheduled task to "Run with highest privileges". Without both the script would not run. I am not 100% sure why only Windows 8 fails miserably without doing this.
The batch file contained only the following code.
start "" "C:\path\to\script.vbs"

Resources