The little loop runs too often - linux-mint

i have wrote a simple Phyton in AutoKey script.
I expected the cursor runs one line down. But the cursor runs many 1000 lines down. That takes some minutes.
for i in range(0, 1):
keyboard.press_key('<down>')
i tried to uninstall other software that could maybe influence the keyboard negative. i uninstalled espanso ( https://espanso.org/install/ ) but it changes nothing.
The result is also visible in this live stream (german voice): https://youtu.be/r9QYQv5h2HU

The Down Key hangs permanently. The Loop was running correct.
Its needet to release it manually by using keyboard.release key('<down>')
for i in range(0, 1):
keyboard.press_key('<down>')
keyboard.release_key('<down>')

Related

Prevent Ctrl+Z deleting last line in SSMS after Script As->Alter View

I'm hoping there's just some way to disable this in SQL Server Management Studio (v17.9.1). When I Script As->Alter a view or stored procedure to a new query window, I can hit Ctrl+Z and it deletes the last line of text! I realize as I'm trying to explain this exactly what's happening: Sql is opening a new window and "pasting" the query line by line. Therefore when you undo you're removing the last line and so on.
This becomes a problem when you say, alter a view, make changes and execute, then decide to undo them all so you just hold Ctrl+Z then realize you've erased half your script instead of just going back to the starting point.
Does anyone know how to disable this or an elegant way of preventing it from happening?
This started out as a comment, but it's getting too long, so...
I don't think you can disable ctrl+z, but just like Newton's third law of motion - for every undo there's an equal and opposite redo - so if you've held ctrl+z pressed for too long, you can always restore the lines that ctrl+z deleted simply by using ctrl+y.
Other options are suggested by GSerg in his comments - you can always keep a copy of the original code in a different query window, or even a simple text editor.
One more option is to first save the content of the new query to a file, so you can always reload it's original state if you've messed things up too much.

AutoHotkey: Could not close the previous instance of this script. Keep waiting?

I've got an AutoHotkey script that presents the following error when I try to run it again:
Could not close the previous instance of this script. Keep waiting?
It's a pretty simple script, with the following settings:
#NoEnv
#SingleInstance force
SendMode Input
DetectHiddenWindows, on
SetWinDelay, -1
I'm launching the script from the command line. I've tried using the /f / /force option and there is no effect.
I want the #SingleInstance Force behaviour described in the docs, which is described as:
Skips the dialog box and replaces the old instance automatically, which is similar in effect to the Reload command.
Turns out the problem was the SetWinDelay instruction.
From the docs:
Although a delay of -1 (no delay at all) is allowed, it is recommended that at least 0 be used, to increase confidence that the script will run correctly even when the CPU is under load.
A delay of 0 internally executes a Sleep(0), which yields the remainder of the script's timeslice to any other process that may need it. If there is none, Sleep(0) will not sleep at all.
When I had it set to -1 the script never had time to process other commands, including whatever exit command was sent to it.
Ensure SetWinDelay is greater than or equal to 0.

Can't Close and Delete Open MSWord 2010 Document (ActiveDocument.Close prevents Kill command from running.)

I'm trying to close the open word document and delete it as part of my DocumentBeforeClose event. I keep running across the following code in my searches (+/- some error trapping statements):
Dim Killfile As String
Killfile = Dir$(ActiveDocument.FullName)
If Len(Dir$(Killfile)) > 0 Then
SetAttr Killfile, vbNormal
ActiveDocument.Close False
Kill Killfile
End if
I've found similar code (well, frankly almost identical code) in several places, and everyone seems to confirm that it works, but I cannot get it to run correctly in my own attempts, regardless of what module I have the code in. When run, the document always closes, but the code also stops there and never gets to the Kill command. In theory the instance of Word is supposed to keep running the script once the document closes; in my case the instance is open, but there's nothing running anymore at that point. Am I doing something obviously wrong here?
If it's helpful, in another version of the code I'm working with I have a Do While loop going through a directory and deleting documents containing "temp.doc" in the name. That code has no trouble running through and deleting closed files, but also will not delete the active/open document after closing.
Is this something I need to place in the Normal module in order for it to work? (Would reeeaally like to avoid that if possible). Thanks for any help!
Editing to add the top few relevant Search Results from Googling "MSWord VBA Delete Open Document":
http://word.tips.net/T001346_Deleting_the_Open_Document_File.html
http://geekgirls.com/2010/02/deleting-an-open-document-in-microsoft-word/
Delete doc when macro finishes
Again, the unifying factor appears to be:
Activedocument.close
Kill WhateverOpenFile
...which just plain doesn't seem to make sense.

MATLAB code break

I have started running a script on MATLAB that takes days to finish. Usually, if I changed my mind and I don't want wait for it to finish and I get content with the intermediate results, I highlight the command window and press Ctrl-C to break the code.
Now, I have run MATLAB. But its desktop got kinda stuck in the background. When I try to restore the desktop from the toolbar, it does not restore. But I know from the task manager that the process is running and is consuming Memory and CPU performance. So, I am kinda stuck. I don't want to kill the process because I need the intermediate values in the workspace, and I can't open the desktop to break the code using ctrl-c.
Is there any solution? For example, is there any command that can be used in the command prompt to act as ctrl-c for MATLAB?
I am using MATLAB R2012b and Windows 8.
Quick try to fix the recent Problem:
Try ty set a higher priority to matlab.exe in the Task Manager. (Right click -> Priority -> Higher than normal). Then see if you can get the window to front.
Some approaches to avoid this problem in future:
Try to optimize your code. For starters look at: http://de.mathworks.com/help/matlab/matlab_prog/vectorization.html
Use Matlab compiler for faster execution: http://de.mathworks.com/products/compiler/
Include some drawnow commands at stratetic positions in the code. This allows matlab to process the Event Queue and capture ctr-C commands.
Save intermediate results to output files. For example you could write an output file all 30 min with your intermediate results. Easyiest way would be just save(filename). Then a .matfile with all your workspace variables is generated. You can than kill the process in the task manager, without loosing too much results.

Oddball issue arising with use of TextWrangler to edit Python 2.7 script which tests multithreading and Queue modules

I'm writing a script in Python 2.7 exploring the use of the multithreading and Queue modules. the script just defines two functions, one of which will be started in a thread instance to fill a Queue, and a second one which will be started in a second thread instance to pull something off the Queue. However, I cannot even get this script to execute, as it chokes on one of the function definitions even before it executes. The code snippet with the problem is:
def listenThread(counter):
while queue.empty() != True:
try:
outcome = queue.get()
print outcome
counter -=1
print counter
except:
return 'queue.get() command loop failing.'
The error message I am getting is:
$ python threading-and-queue-test.py
File "threading-and-queue-test.py", line 34
except:
^
IndentationError: unindent does not match any outer indentation level
$
I've searched SO and checked the docs for correct formation of the try-except construct, and it seems OK. I had earlier versions of the code (without the try-except ) working, so I am getting suspicious about the text editor, TextWrangler v4.0.1.
Can anyone suggest a debug approach or code correction?
Thanks!
Red
As you have already suspected, it is most likely an indentation error. Your text editor is probably mixing the use of tabs and spaces. Replace all tabs with spaces (or vice versa though the standard in python is 4 spaces) and you should see the error disappear.
For those who find this question later like I did it's easy to fix TextWrangler's settings and stop this issue altogether; Go to "Preferences" -> "Editor Defaults" -> "Auto-expand tabs" then set tabs to 4 spaces. Restart TextWrangler for changes to take affect. For existing documents that continue giving you a problem read this.