I'm looking for a way to run a loop in TCL shell background (meaning - an infinite loop calling some function), but I can't find a way to do it.
The proc is a simple proc releasing all possible licenses from the user (we have a shortage of licenses here at work and we constantly fighting who's going to get them).
The loop itself is simple:
while {1} {
after 60000
clr_lic
}
But how can I make it run in the background so I'll be able to run other commands as well?
Are you running an event loop? If you are, you can do this with the every procedure:
proc every {ms script} {
after $ms [info level 0]
uplevel "#0" $script
# Double quotes just for syntax highlighting…
}
every 60000 clr_lic
Otherwise, things get awkward: you'd have to think about spinning up a thread or a subprocess and… well, it all gets a lot more awkward as then you're in a strongly segregated context and have to do a lot more work (well, usually).
When testing the code above, I used this:
every 500 {
puts "Hi there, world!"
}
vwait forever; # Conventional way to run the event loop in tclsh
And I got quite a lot of messages written out; it's flexible and easy.
Try appending an ampersand (&) when invoking your script. This will run it in background and you're be able to run any command you like.
Related
I thought this question would have been asked already, but I can't find it, so here goes: I've noticed that numpy.save commands only trigger, i.e. the file to-be-created is actually created, after the entire code has finished running. This is bad when the code takes days or weeks to run, and I want to pin down exactly which function, and what arguments into the function, are causing the bottleneck.
There is a similar issue with the print() command; it doesn't write to the output file immediately but rather waits until the entire code is finished before writing. I can force it to write immediately with this code:
def printnow(*messages):
w=open("output.log","a")
for message in messages:
w.write(str(message))
w.write(" ")
w.write("\n")
w.close()
I was wondering whether it's possible to do an analogous thing, i.e. force an immediate save, for numpy arrays. No need for appending; overwriting with the current value of the numpy array is fine.
If it makes a difference, I'm not running the code on my personal computer but a group server, which I issue commands to and check on using Putty and WinSCP.
Thanks
Edit: I tried another package, shelve, and it encounters the same problem. I create a global variable called function_calls and initialize it to 0. Then, at the start of the function that I suspect is causing the bottleneck, I put in the following code:
global function_calls
file='function_inputs'+str(function_calls)
function_shelf=shelve.open(file,'n')
for key in dir():
function_shelf[key]=locals()[key]
function_calls+=1
This code is intended to create a new file that saves the function inputs, each time the function is called. Unfortunately, 9 hours into starting the run, no files have been created. So I suspect Python is just waiting until the whole run is finished before creating the files I asked it to.
Is there a way to put a time.sleep in a minecraft function for Minecraft bedrock like in python?
For example:
/say this is a test!
time.sleep(5)
/say This is executed after the time.sleep
Please specify what a minecraft function is.
I assume you are using Minecraft: Java edition, to add delays in java you can use java.util.concurrent.TimeUnit
TimeUnit.SECONDS.sleep(1); Sleeps for one second.
TimeUnit.MINUTE.sleep(1); Sleeps for one minute.
You can make a sleep function but not how you tried to do it. I made a video for you to explain what I mean.
Give yourself a command block:
/give #s command_block
Place it and put your command into the window.
Place a command block next to it and put your second command in the window.
Change the presets to repeating always active and conditional.
Put the tick value in the last box. 20 ticks are equal to 1 second.
Use hopper clocks for timings, works as a charm
I'm trying to send the output of my code to an inactive application using Auto Hotkey on my computer so I don't have to be on the screen and can do other stuff. How would I go about implementing it?
F1::
stop := 0
Loop
{
Send, z
Sleep 500
}until Stop
return
F2::Stop := 1
This is the code I have down so far, any help?
ControlSending might work. It's basically a hit or miss. It'll work for some applications, and for some it wont.
It'll be worth a try for you though.
Also, you're going to want to use a timer as opposed to looping in a hotkey thread. Timer is intended just for something like this and what you were doing is kind of bad practice for various reasons.
;timer runs the user-defined function "SendZ" every 500ms
F1::SetTimer, SendZ, 500
F2::SetTimer, SendZ, Off
SendZ()
{
ControlSend, , z, % "ahk_exe notepad.exe"
}
As a bonus, we can even write a sweet one liner to toggle on/off that timer by using a ternary:
F1::SetTimer, SendZ, % (Toggle:=!Toggle) ? 500 : "Off"
If that doesn't make sense to you, and you're interested, you can read a lengthy previous explanation of mine about it here.
I currently have some code that requires running CFRunLoopRun().
This runs indefinitely. I would like to replace it with something that only runs for a set amount of time, say 30 seconds.
I tried CFRunLoopRunInMode(), but it exits immediately.
CFRunLoopRun(); // Works but never stops, I need to stop after 30s
CFStringRef mode = (__bridge CFStringRef)#"mode";
CFTimeInterval timeInterval = 10.0;
CFRunLoopRunInMode(mode, timeInterval, FALSE); // Doesn't work, syntax is wrong?, stops immediately
You are using a custom mode. It looks like you're just making it up for this one call. That would suggest that there are no input sources scheduled in that mode. All of the run-loop run functions exit immediately if there are no input sources.
CFRunLoopRunInMode() actually returns a value indicating why it exited. You should examine that.
The difference with CFRunLoopRun() is that it runs the run loop in the default mode (kCFRunLoopDefaultMode), not your custom mode. That mode almost certainly does have input sources scheduled (at least, assuming this is the main thread and thus the main run loop).
So, you could do this:
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10.0, FALSE);
All of that said, running the run loop for a fixed time period is rarely the right approach. What are you actually trying to achieve? What led you to conclude that you need to run the run loop for 10 seconds? Why not just return to the normal event loop and use a timer to do some work in 10 seconds?
I know how to do this in gdb. I'd attach, and follow with:
break myfunction
commands
return
cont
end
cont
I'm wondering if there's a way of doing this in c? I already have my code working for reading memory addresses and writing to memory addresses. And it automatically finds the pid and does related stuff. I'm stuck with implementing that use of breakpoints.
If you are talking about some sort of hand-written debugger, you can use IP value to set a breakpoint; Literally, when IP hits some certain value, you stop the program being debugged and perform some routine (for example, heading away to debugger process). To use function names, you should use symbol tables like it is done in GDB.
It's not quite clear what you are trying to achieve.
The GDB sequence you've show will simply make myfunction immediately return.
Assuming you want your mini-debugger to have the same effect, simply write the opcode for ret (0xC3 on x86) to the address of myfunction; no need to do the breakpoint at all.