In Python the import path contains . (working directory). Importing a
module basically means executing it. That is why your importing of queue
from urlfilter.py resulted in queue being executed. To avoid accidental
execution of scripts by importing, you can check the __name__ variable for
the value '__main__'.
if __name__ == '__main__':
do_not_execute_this_during_import()
This is one of the problems recently discussed in vim-dev and in some other
topics. This behavior requires patching vim source to have eventloop in a
separate thread, but there is no patch for this yet.
Currently there is no way to do this. Some running python scripts may be
interrupted by sending a SIGINT, but not all.
You can check the exit code of another process with the child error
variable $?. For example:
system("perl foo.pl");
my $exit_val = $? >> 8; # now contains the exit value of the perl
script
Read the documentation for more info.
Try commands module for py2.3.4, note that this module has been deprecated
since py2.6:
Use commands.getoutput:
import commands
answer = commands.getoutput('./a.sh')
You could use cwd parameter, to run scriptB in its directory:
import os
from subprocess import check_call
check_call([scriptB], cwd=os.path.dirname(scriptB))
Use raw_input (Use input in Python 3.x). Pressing Ctrl+D will cause
EOFError exception.
try:
raw_input()
except EOFError:
pass
UPDATE
Use atexit - Exit handlers:
import atexit
def quit_gracefully():
print 'Bye'
atexit.register(quit_grace
You can have scripts execute in order by chaining the command with
&&
&& makes sure the first command has completed before moving onto
the other sin the chains. As opposed to & which will execute them all
even if the prior ones fail.
first.sh echoes I am First
second.sh echoes I am Second
Command
sh first.sh && sh second.sh
Output
I am First
I am Second
You can tie this into a cron job if you wish to have it execute at certains
times etc.
I know Python pretty well, but I've hardly ever used Ruby...
There are several things wrong here:
Python imports are done for module names; you are trying to import a
filename instead.
Normally, you'd add the directory to the #{Rails.root}/lib directory to the
Python module search path (either with the PYTHONPATH environment variable
or by manipulating the sys.modules list from Python code), but you are
trying to import the setup script here.
You'd run python setup.py install to install the library. Or, much better,
use pip or easy_install to install the package for you.
colorific is a command-line utility. It doesn't appear to provide an API to
import. I'd not use a Ruby-to-Python bridge here, just run the tool using
the Ruby equivalent of the Python subprocess module; as a separate
ticketfieldentry.bind("<Double-Button-1>", lambda e:
Try to change your javascript as follows:
<script type="text/javascript">
function slideToggle(e, ui) {
debugger;
//find the right control to slideToggle
var ct = e.currentTarget;
var controlHolder = ct.parentNode; //up the dom one element
$(controlHolder).find(".expandableContent").slideToggle(500);
//back down the dom to the element we want to animate
}
$(document).ready(function () {
//find the right control to hide
var pare = $('.helpControlHolder');
pare.find(".expandableContent").hide();
});
$(function(){
$(".expandableHeading").click(function (e, ui) {
e.preventDefault();
slideToggle(e, ui);
});
});
</script>
Hope it helps.
The child process flushes its output buffers on exit but the prints from
the parent are still in the parent's buffer. The solution is to flush the
parent buffers before running the child:
print("Starting script...")
sys.stdout.flush()
build.run()
This turned out to be a problem of relative paths confusing coverage when
the measured script is run from another directory. Coverage result files
ended up in that directory, instead of the root directory of the project.
To solve this, I stopped using pytest-cov, and used pure coverage instead.
I used full paths instead of relative paths wherever relevant.
So, e.g.
define the environment variable necessary to enable subprocess coverage via
export COVERAGE_PROCESS_START=/full/path/to/.coveragerc.
In the .coveragerc, the coverage result file is specified via
[run]
data_file = /full/path/to/.coverage
and any --source and --include options should use full paths, too.
Then it was possible to get correct coverage measurement.
Your problem is in the if random.randrange == some_range checks. Actually,
your code has several problems:
First, you need to actually call the randrange function, and it needs at
least one parameter: the stop value for your range (which defaults to
starting at 0). See the randrange documentation for details.
Second, randrange() returns a number, but you're comparing its result to a
list. This will always be False: in Python, 3 and [3] are not the same
value. What I suspect you want is to check if your random value is
contained in the list. One way would be if random_value in some_range,
because the in operator searches a list to see if it contains the value you
passed in. But this would be slow on really large ranges; a much better
approach would be to stop using ranges and start using
You should be able to do this quite easily using getJSON.
Something similar to this should do the trick:
$.getJSON( url ,
function(data) {
//Do something with data here
alert(data);
});
EDIT: The answer from the link below that I find most interesting is this
one:
$.ajax({
url: url,
dataType: 'script',
success: success,
async: false
});
It seems that disabling the asynchronous part of ajax will execute the
script first, then the callback afterwords, instead of doing them
synchronously.
That's not the cURL problem.
While Website is UP - Request Status Gets 200(OK) and Script executes Fine
But
While Website is DOWN - The AJAX Request keeps sending/waiting for request
until it gets 200(OK) Status.
Try Avoiding AJAX in this case and use PHP to send cURL Request.
They're technically not built as the makefile is parsed. See the GNU make
manual, section How Makefiles are Remade. Once make finishes parsing all
the makefiles, it will perform a pass where it makes sure that all the
included makefiles are up to date, by treating them all as if they were
targets and trying to rebuild them. That's what you're seeing.
If any makefile has changed, then make will re-execute itself from scratch
so it can re-read the contents of the updated makefiles.
The solution you have (where you check for the clean target, and any other
targets you don't want to force a rebuild of makefiles, and if it's found
you either don't do the include or you don't provide the rules to rebuild
the makefiles) is the recommended solution.
Remember that rules like clean, all, etc.
Note: Launcher is broken and should be fixed. Thus, any "solution" will be
a hack.
One thought is to check $PPID in various places in the script. If it is
set to 1 (init), then exit the script.
I don't understand the use of control-X. That is not going to generate any
tty signal. I guess that is what you want. Perhaps the tty is also in raw
mode. But you might consider hooking control-X up to one of the various
tty signals like SIGINT. e.g. stty intr ^X but you will also need to
remember to unset it with stty intr ^C
Last, you could wrap the script in a script and use the technique to kill
the child and exit. e.g. (untested)
#!/bin/ksh
# launch original program in background
/path/to/real/program "$@" &
# get child's pid
child=$!
while : ; do
# when we become an orphan
The output of the process can be found by using getInputStream on the
returned Process from the exec call.
are you sure postgres is listening on a socket? are you sure the username
and password is right?
I would be inclined to try something like
require 'pg'
puts PG::Connection.ping(:dbname => 'oData',:user => 'am',:password
=> '')
puts "trying with tcp"
puts PG::Connection.ping(:dbname => 'oData',:user => 'am',:password
=> '', :port => 5432)
you need to give it the full path to the script that you are trying to
call, if you want to do this dynamically (and you're in the same
directory), you can do:
import os
full_path = os.path.abspath('kvadrat.py')