My app is written in Python 2.7 and wxPython 2.8, and accesses a MySQL database. I have had issues with the program freezing when doing an add via:-
cursor.execute(sql ([idSession, TestDateTime, DataBLOb]))
Although this is in try: - except: construct it never executes the except portion. I have run this section from the command line and got:-
_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')
Obviously I need to investigate the cause of the error but how can I get my software to execute the except: code rather than just freeze!
To solve this, you need to create a new Thread. Look the code:
from threading import Thread
class Spam(wx.Frame):
def doStuff(self, arg1,arg2,arg3)
# Do Something...
try:
cursor.execute(sql ([idSession, TestDateTime, DataBLOb]))
except Exception a e:
# Do the treatments or show a dialog
def ButtonClick(self, event): # Assuming a button like "do this operation"
t = Thread(target=self.doStuff,args=(arg1,arg2,arg3))
t.start()
Observation:
The function doStuff need to be free of errors, if some error raised and not is treated will create a deadlock, or a zombie thread.
Related
I have a Dash app with a standard layout which I run with standard invocation:
#wsgi.py
from __init__ import app
from __init__ import server
if __name__ == "__main__":
app.run_server(port=5000, debug = True)
I would like to run a once-a-day updater script for some calculations with a general schematic like this:
#one of the application pages .py
def update_df_daily_loop():
while True:
if time since last update > 24h:
run update
last updated = now
else:
sleep for 15 minutes
#tried invoking the thread like this - but it blocks the server from starting
thread0 = threading.Thread(target=update_df_daily_loop)
thread0.start()
thread0.join()
Where should I put the invokation? If I just run it as a thread it blocks the server from ever starting.
I have a function interpolate_to_particles written in c and wrapped with ctypes. I want to use dask.delayed to make a series of calls to this function.
The code runs successfully without dask
# Interpolate w/o dask
result = interpolate_to_particles(arg1, arg2, arg3)
and with the distributed schedular in single-threaded mode
# Interpolate w/ dask
from dask.distributed import Client
client = Client()
result = dask.delayed(interpolate_to_particles)(arg1, arg2, arg3)
result_c = result.compute(scheduler='single-threaded')
but if I instead call
result_c = result.compute()
I get the following KeyError:
> Traceback (most recent call last): File
> "/path/to/lib/python3.6/site-packages/distributed/worker.py",
> line 3287, in dumps_function
> result = cache_dumps[func] File "/path/to/lib/python3.6/site-packages/distributed/utils.py",
> line 1518, in __getitem__
> value = super().__getitem__(key) File "/path/to/lib/python3.6/collections/__init__.py",
> line 991, in __getitem__
> raise KeyError(key) KeyError: <function interpolate_to_particles at 0x1228ce510>
The worker logs accessed from the dask dashboard do not provide any information. Actually, I do not see any information that the workers have done anything besides starting up.
Any ideas on what could be occurring, or suggested tools that I can use to further debug? Thanks!
Given your comments it sounds like your function does not serialize well. To test this, you might try pickling the function in one process, and try unpickling it in another.
>>> import pickle
>>> print(pickle.dumps(interpolate_to_particles))
b'some bytes printed out here'
And then in another process
>>> import pickle
>>> interpolate_to_particles = pickle.loads(b'the same bytes you had before')
If this doesn't work then you'll know that that's your problem. I would encourage you to look up "how to make sure that ctypes functions are serializable" or something similar, or ask another question with that smaller scope here on Stack Overflow.
I'm currently trying to run NERVE a vaccine development program that is made up of Perl scripts and have trouble getting it to run properly. I've downloaded and installed all prerequisites but every time I reach the mysql step of the code, it crashes, and an error message says: Can't locate object method "connect" via package "Mysql" (perhaps you forgot to load "Mysql"?) at ./NERVE line 340, line 5. I took a look at the code and changed "use mysql" to "use DBI" and "use DBD:mysql" but then I get the error: Can't use string ("") as a HASH ref while "strict refs" in use at /usr/local/lib/perl/5.14.2/DBI.pm line 604, line 5.
I would appreciate if anyone could look the code over for the mysql section and give me advice on how to fix it so I can run the program properly. I tried emailing the developers but no response so I'm hoping you guys can help me.
Below is the perl code for NERVE for the mysql section.
use mysql;
$db=Mysql->connect("$host","$database","$user","$password");
if(!$db || (!$host || !$database || !$user || !$password)){
print "\nAttention: mysql connection parameters are missing or not correct!\n";
print "I need you to specify: host, database, user, password;\n";
print "You can do it now typing them right in that order and separeted only by comma;\n";
print "For example:localhost,Pathogens,sandro,xvzhs\n";
print "So, your Mysql connection settings are (type q to quit):";
while (!($db && $mysql =~ /,/) & $mysql ne "q"){
chomp($mysql = <STDIN>);
die "Ok,let's quit this work! Call me when your mind is clearer about Mysql parameters! Bye :-)\n" if $mysql eq "q";
($host,$database,$user,$password) = split (',',$mysql);
$db=Mysql->connect("$host","$database","$user","$password");
last if($db && $mysql =~ /,/);
print "\nMysql connection settings still not correct!\n";
print "Remember: host, database, user, password, separeted only by comma.\n";
print "For example:localhost,Pathogens,sandro,xvzhs\n";
print "Please, try again:";
}
print "Ok, Mysql connection to \"$database\" database was successful!\n";
}
The error message is correct. You are attempting to use a module named , but you never loaded it. Change
use mysql;
to
use Mysql;
to use that module. In the comments, you mention that results in
Can't locate Mysql.pm in #INC
Unless you have reason to believe the module is installed, that indicates it needs to be installed[1]
That module used to be part of the DBD-mysql distribution, but it's obsolete. It's so ancient it was removed from DBD some years ago. To obtain it, you will need to downgrade your DBD-mysql distribution to version 3.0008.
That's pretty awful thing to do. The script should have DBI instead.
cjm points
since the Mysql.pm in 3.0008 is just a compatibility layer using DBI under the hood, you should be able to install Mysql.pm & Mysql/Statement.pm from that old dist along with a current DBD-mysql.
So if you extract Mysql.pm from the distro I linked above as /usr/lib/perl5/Mysql.pm and Mysql/Statement.pm as /usr/lib/perl5/Mysql/Statement.pm, you should have an easy pain-free solution.
In newer versions of Perl, the error message has been improved. It now reads as follows:
Can't locate Mysql.pm in #INC (you may need to install the Mysql module)
I'm trying to learn Shoes and decided to make a simple GUI to run a SQL-script line-by-line.
My problem is that in GUI pressing the button, which executes my function, freezes the GUI for the time it takes the function to execute the script.
With long scripts this might take several minutes.
Someone had a similar problem (http://www.stackoverflow.com/questions/958662/shoes-and-heavy-operation-in-separate-thread) and the suggestion was just to put intensive stuff under a Thread: if I copy the math-code from previously mentioned thread and replace my mysql-code the GUI works without freezing, so that probably hints to a problem with how I'm using the mysql-adapter?
Below is a simplified version of the code:
problem.rb:
# copy the mysql-gem if not in gem-folder already
Shoes.setup do
gem 'mysql'
end
require "mysql"
# the function that does the mysql stuff
def someFunction
con = Mysql::real_connect("myserver", "user", "pass", "db")
scriptFile = File.open("myfile.sql", "r")
script = scriptFile.read
scriptFile.close
result = []
script.each_line do |line|
result << con.query(line)
end
return result
end
# the Shoes app with the Thread
Shoes.app do
stack do
button "Execute someFunction" do
Thread.start do
result = someFunction
para "Done!"
end
end
end
stack do
button "Can't click me when GUI is frozen" do
alert "GUI wasn't frozen?"
end
end
end
I think the problem arises from scheduling which is done by ruby, not by the operating system. Probably just a special case with shoes + mysql.
As a workaround i'd suggest you spawn a separate process for the script and use socket or file based communication between the processes.
I'm trying to simulate a testbench. I'm not getting the waveforms also i'm getting the following warning message at the prompt. Is it because of the=is warning that my code does not simulate?
** Warning: (vsim-WLF-5000) WLF file currently in use: vsim.wlf
# File in use by: Hostname: ProcessID: 0
# Attempting to use alternate WLF file "./wlftazxa4k".
# ** Warning: (vsim-WLF-5001) Could not open WLF file: vsim.wlf
# Using alternate file: ./wlftazxa4k
run
I'm also includng my testbench as follows:
module dec_tb;
reg [63:0] FROM_IF_ID;
reg CLK;
wire [117:0] TO_ID_HMIC;
integer k=0;
inst_decode id(.from_if_id(FROM_IF_ID),.clk(CLK),.to_id_hmic(TO_ID_HMIC));
initial
begin
$monitor($time,"clk=%b, fifid=%b, tidhm=%b",CLK,FROM_IF_ID,TO_ID_HMIC);
$display("qf");
CLK= 0;
FROM_IF_ID[35:32]=4'b1100;
FROM_IF_ID[63:36]=28'b0000_10000_00100_01000_00010_0001;
end
always
begin
#10 CLK= ~CLK;
end
always #(posedge CLK)
begin
$display (" TO_ID_HMIC= %b", TO_ID_HMIC);
FROM_IF_ID[k] =~FROM_IF_ID[k];
k=k+1;
#500 $finish;
end
endmodule
If that's the only message, then the simulation ran, and you can find the waves in the specified alternate file (wlftazxa4k).
If you want to fix the problem so the waves show up in vsim.wlf, here are a few things to try:
Make sure you don't have any stray modelsim processes running
Make sure you don't have vsim.wlf open in a waveform viewer
Delete vsim.wlf manually and rerun
I had this problem also. As it turns out, the directory that my vsim files were located in was full (school partition, 600mb allowed space). After clearing out some old files i had lying around, the program worked fine.
Your your quiz:
Run you simulation
Quit your simulation with gui or command: quit -sim
Goto step 1 and have fun.
You can remove cache file create by modelsim.