I'm trying to make a htop like in ncurses.
I'm doing an infinite loop to have the information updating and a condition to make it stop.
But it doesn't update itself because it wants to check the input before.
What shall I do ?
htop author here -- htop itself is written in ncurses. You need to use the halfdelay() function to make the input function timeout.
See http://linux.die.net/man/3/halfdelay
When you are initializing the curses parameters, you could use the next function
timeout(TIME_IN_MILLIS);
code sample:
initscr();
cbreak();
noecho();
nonl();
timeout(1000);
mvprintw( 1, 1, "%s", "Hello World!" );
refresh();
getch();
endwin();
Related
I want to run a single step in the my scenarios for multiple times. My scenario consists of connect and disconnect steps.
I have used the while loop to do a work around for it,but was helpless, as the test fails with 'Ambiguous match of "I tap on disconnect button":'. This may be reason as the test executes the same line "I tap on disconnect button" or "I tap on connect" multiple,which Gerkhin may not support as the language is repeating while the loop is running.
Here are the steps:
Then I select the item from the list
Then I tap on disconnect button
Then I tap on connect to reconnect
I want second two steps to be executes 10 times when the run the scenarios.
Can someone help on this.
You can make it like this
Then I restart connection
step def:
$i = 0
$num = 10
while $i < $num do
#YOUR CODE HERE
#DISCONNECT
sleep(3)
#CONNECT
puts("Inside the loop i = #$i" )
$i +=1
end
It should work if you use only one element of UI and you dont change it, on the other hand to help you in future if you have problem with multiply different elements in calabash-android use Table calabash-android construction.
Could you not just make the step definition
Then I reconnect 5 times
Step def
Then /^I reconnect (.*) times$/ do |repetitions|
repetition.times do
... your code here
end
end
I am working in a TCL automation environent at my workplace.
I'm trying to run a delayed command in my script using "after".
The problem i encounter is that when i try to specify commands with variables inside a code block under an "after" , the vars are not recognized and i get an error message.
I'll quote the relevant parts of the code.
proc test_script1 {{bh0 0} ...more vars....} {
.
.
.
after [expr 20000] {
set some_value[ ns1::probe_TCP_connections $bh0 $main_duration 1 15] }
puts "the value i got is $some_value"
}
And i seem to get an error:
can't read "some_value": no such variable
Can anyone suggets what is the problem , and how to oversome it?
thx
You can capture the values of local variables with the help of apply (and it's advisable to use list to build callbacks when they get even slightly non-trivial). Since the body of an apply is a lambda expression with its own scope — a little nameless procedure — you have to use global in it to access state that will persist, and in any case after callbacks are called from the global namespace always (since the mechanism doesn't know how to keep arbitrary stack frames around for the duration of the asynchronous operation).
after 20000 [list apply {{bh0 main_duration} {
global some_value
set some_value [ns1::probe_TCP_connections $bh0 $main_duration 1 15]
}} $bh0 $main_duration]
global some_value
vwait some_value
puts "The value was changed to $some_value"
It's possible to get even more sophisticated, especially in Tcl 8.6 which has a coroutine system that can be used to hide the complexity of using continuation passing style programming.
Here is a proc that will do something similar to what you're trying to do:
proc foo {} {
# Make 'a' available to both the global scope and local scope
global a
# This is to check the current level
puts "Current level: [info level]"
# The command to be run in 500 ms, and I have added another check for the level
after 500 {puts "Current level: [info level]"; set a 100}
# Wait for further execution until the global variable 'a' changes
vwait a
# Prints a
puts "Value of \$a: $a"
}
The output of the above will be:
Current level: 1
# After 500 ms, the below will print
Current level: 0
Value of $a: 100
When you use after, the variable a is being created in the global scope, that is not accessible to the proc unless explicitly given access. One of the simplest ways is to first make sure that a within the proc is accessible both globally and locally, with global (level 0).
I've tried some variations of this without luck:
Process, Exist, Game.exe
Process, Close, GamePatcher.exe
Return
I'm playing a game where the launcher/patcher stays open even after the game launches.
Any ideas?
A While loop should help you out. Here is a solution using a little ProcExists function that can be reused.
Loop
{
If ProcExists("Game.exe") and ProcExists("GamePatcher.exe")
break
Sleep 500
}
; Both procs exist, wait for Game to close.
While ProcExists("Game.exe")
Sleep 500
Process, Close, GamePatcher.exe
Reload ; Reloads waiting for both to exist again
ProcExists(p)
{
Process, Exist, % p
Return ErrorLevel
}
If you want this to perform continuously (keep the script running at all times), it would be best to implement SetTimer like this:
#Persistent
SetTimer, checkGame, 1000
Return
CheckGame:
If ! ProcExists("Game.exe")
Process, Close, GamePatcher.exe
ProcExists(p)
{
Process, Exist, % p
Return ErrorLevel
}
I am using server push in Wt and I am trying to push a new chart with the following code:
Wt::WApplication::UpdateLock uiLock(app);
if (uiLock){
chart_ste = new ScatterPlotExample(this,10*asf.get_outputSamplingRate());
app->triggerUpdate();
}
but it waits for the program to end and then it prints it whereas the following code in the same program pushes the word "Demokritus every 0.5 secs as it should do:
for (int i=0; i<10; i++)
{
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
Wt::WApplication::UpdateLock uiLock(app);
if (uiLock) {
showFileName = new WText(this);
showFileName->setText(boost::lexical_cast<std::string>("Demokritus"));
app->triggerUpdate();
}
}
What might be my mistake?
The documentation for triggerUpdate mentions that "The update is not immediate, and thus changes that happen after this call will equally be pushed to the client." If the changes are not immediate, it could be that the first piece of code continuously tries to push updates as fast as your CPU will allow it, so it never gets to the server because a new update overwrites the last and it begins waiting again. Try adding boost::this_thread::sleep(boost::posix_time::milliseconds(500)); to the first piece of code to see if that helps.
I've done a project once where I needed to update a chart every second with new data and had a very similar setup to yours. I put in the sleep from the start because I did not want my boost thread to use too much CPU.
Also, it is unclear if the first piece of code is in a bigger loop, if it is, you probably shouldn't make a new chart every time, but create it before hand and then update it with data. I hope some of this helps.
I have erlang application. In this application i run process with spawn(?MODULE, my_foo, [my_param1, my_param2, my_param3]).
And my_foo:
my_foo(my_param1, my_param2, my_param3) ->
...
some code here
...
ok.
When i open etop i see that this my_foo/3 function status: proc_lib:sync_wait/2
Than i try to put exit(self(), normal) in the end of my function, but i see same behavior: proc_lib:sync_wait/2 in etop.
How can i kill or exit process correctly?
Thank you.
Note that exit(Pid, Reason) and exit(Reason) do NOT do the same thing if Pid is the process itself. exit/1 tells the current process to exit - from the inside if you like - while exit/2 sends an exit signal to the process, even if the process is itself. So when you do exit(self(), normal) you are actually sending the normal exit signal to yourself, which is ignored.
In this case putting the exit call at the end of the function should not make any difference as the process automatically dies (with reason normal) when the function with which it was started ends. It seems like the process is suspended somewhere before that.
proc_lib:sync_wait/2 is called inside proc_lib:start/start_link and sits and waits for the spawned process to do proc_lib:init_ack/1/2 to return the return value for start. It would appear that your process does not call init_ack.
Based on the limited information that you give in the question I would suspect that your process hasn't finished running yet.
Normally you don't need to add exit/2 to your process. It will exit automatically when the function has finished running.
You probably have a long running call in some code here that has not finished running. I recommend that you add logging information and see where you are stuck.