When you encounter 'ClassName matching query does not exist' error in Django, it means that somewhere you have such code:
item = ClassName.objects.get(key=value)
but there's no item that satisfies key=value. So it gives this error. Be aware of this. There are some other sites which makes you confuse although this is a very simple error
Tuesday, December 27, 2011
Thursday, December 16, 2010
ParallelPython vs multiprocessing
Today I'm working on parallelisation of a process I have written. Process is simply a text conversion. I have a translator class, organism directories and files inside these directories. What I want to do is to split the data among the processors and perform the operation faster.
To do this, I tested multiprocessing and ParallelPython modules of python. Without using these modules, it took 38 seconds to perform the task whereas with the help of these modules, it went down to 29 seconds(multiprocessing) and 30 seconds (ParallelPython). Not a great deal but better than nothing. By the way, ParallelPython is way too complicated compared to multiprocessing.
Here is the code for ParallelPython:
ParallelPython requires you to tell him the modules the functions requires. I didn't like that.
And here is the code for multiprocessing:
To do this, I tested multiprocessing and ParallelPython modules of python. Without using these modules, it took 38 seconds to perform the task whereas with the help of these modules, it went down to 29 seconds(multiprocessing) and 30 seconds (ParallelPython). Not a great deal but better than nothing. By the way, ParallelPython is way too complicated compared to multiprocessing.
Here is the code for ParallelPython:
import translator
import os
from utils.pp import pp
base = "/some/path"
organisms = [ "organism1", "organism2", ...]
def convert_organism(base, organism):
t = translator.BiogridOspreyTranslator()
# uses os module here
t.translate()
if __name__ == '__main__':
job_server = pp.Server(ppservers=())
jobs = [(organism, job_server.submit(convert_organism, (base, organism,), (), ("os","translator",))) for organism in organisms]
for organism, job in jobs:
job()
ParallelPython requires you to tell him the modules the functions requires. I didn't like that.
And here is the code for multiprocessing:
from translator import *
import os
from multiprocessing import Pool
base = "/some/path"
organisms = [ "organism1", "organism2", ...]
def convert_organism(organism):
t = BiogridOspreyTranslator()
# uses os module here
t.translate()
if __name__ == '__main__':
pool = Pool(processes = 2)
pool.map(convert_organism, organisms)
Tuesday, December 7, 2010
Uploading on sourceforge
Today, we're trying to publish our project Robinviz. It'll be a 1.0-beta version seperately for windows/linux source/binary. Binary files are around 400MB so it's a bit hard to upload it. Google Code -which we use for project management- limits the maximum file size for uploads. So we had to switch to sourceforge. But uploading on http was still a problem. So I found this solution: Rsync over SSH
At first, I found it hard to understand the URL format but then understood and wanted to share it with you. With the following command, I was able to send my 400MB file with resume support:
rsync -avP -e ssh robinviz-1.0-beta-linux-binary.tar.gz aladagemre,robinviz@frs.sourceforge.net:/home/frs/project/r/ro/robinviz/linux-1.0-beta
robinviz-1.0-beta-linux-binary.tar.gz: filename
aladagemre: username on sourceforge
robinviz: project name
/r/ro/robinviz: the first letter, the first two letters and all letters of the project joined by /
linux-1.0-beta: the folder I'd like to put my file in.
Hope it's useful.
At first, I found it hard to understand the URL format but then understood and wanted to share it with you. With the following command, I was able to send my 400MB file with resume support:
rsync -avP -e ssh robinviz-1.0-beta-linux-binary.tar.gz aladagemre,robinviz@frs.sourceforge.net:/home/frs/project/r/ro/robinviz/linux-1.0-beta
robinviz-1.0-beta-linux-binary.tar.gz: filename
aladagemre: username on sourceforge
robinviz: project name
/r/ro/robinviz: the first letter, the first two letters and all letters of the project joined by /
linux-1.0-beta: the folder I'd like to put my file in.
Hope it's useful.
Saturday, October 30, 2010
Dell Wireless 1515 Wireless-N Adapter and WPA timeout on Vista
I'm using a Dell Wireless 1515 Wireless-N Adapter and having connection problems in Vista. When I use WPA for authentication, it doesn't connect to my wireless network and says authentication failed due to timeout. Sometimes it doesn't connect and very rarely it connects. When I looked at the Event viewer, I saw the following details:
After a long research, I thought that I found a way to fix that. I went to Dell drivers site and wrote my laptop Service tag to get appropriate driver updates. I downloaded the one for my wireless adapter: R198377.exe. The reason why the research was long is that I had to do it on another OS and wanted to find a sound solution not to fail and return back. The dates for the driver were earlier than the date I purchased my laptop but it seems like the drivers coming with it are pretty old.
After installing that, my wireless card -surprisingly- immediately connected to the wireless network. I was gonna say "Well done!" but it turned out to be a coincidence that it worked! After a restart, it was the same problem again. Re-installing driver didn't work. Sigh.
I don't know what to do with this.
Detailed root cause:
Layer 2 security key exchange did not generate multicast keys before timeout
After a long research, I thought that I found a way to fix that. I went to Dell drivers site and wrote my laptop Service tag to get appropriate driver updates. I downloaded the one for my wireless adapter: R198377.exe. The reason why the research was long is that I had to do it on another OS and wanted to find a sound solution not to fail and return back. The dates for the driver were earlier than the date I purchased my laptop but it seems like the drivers coming with it are pretty old.
After installing that, my wireless card -surprisingly- immediately connected to the wireless network. I was gonna say "Well done!" but it turned out to be a coincidence that it worked! After a restart, it was the same problem again. Re-installing driver didn't work. Sigh.
I don't know what to do with this.
Sunday, September 5, 2010
Keyword Argument Injection with Python Decorators
In most of the object oriented codes we write, we need to set class variables to the given argument values and this is a very line-consuming thing. See what I mean:
To get over these redundant lines, I found a solution using decorators:
args dictionary contains the arguments and kwargs dictionary contains the keyword arguments. arg[0] corresponds to self argument. So what we do is we update self.__dict__ with {'x':4, 'y':5,'z':6,'t':7} where self corresponds to the Test instance. This way, bulky self.x = x, etc. codes are eliminated.
I don't know if any built-it decorator like this exists in Python libraries but it seems like I'll be using this a lot.
class Test:
def __init__(self, x, y, z, t):
self.x = x
self.y = y
self.z = z
self.t = t
print x,y,z,t
To get over these redundant lines, I found a solution using decorators:
def injectArguments(inFunction):
def outFunction(*args,**kwargs):
_self = args[0]
_self.__dict__.update(kwargs)
inFunction(*args,**kwargs)
return outFunction
class Test:
@injectArguments
def __init__(self, x, y, z, t):
print self.x,self.y,self.z,self.t
@injectArguments
def fonksiyon(self, ad):
print "Ad:",self.ad
t = Test(x=4, y=5, z=6, t=7)
t.fonksiyon(ad="Emre")
args dictionary contains the arguments and kwargs dictionary contains the keyword arguments. arg[0] corresponds to self argument. So what we do is we update self.__dict__ with {'x':4, 'y':5,'z':6,'t':7} where self corresponds to the Test instance. This way, bulky self.x = x, etc. codes are eliminated.
I don't know if any built-it decorator like this exists in Python libraries but it seems like I'll be using this a lot.
Thursday, July 8, 2010
QActionGroup and exclusive menu actions
Today I was working on exclusive menu action selection in PyQt4 and got stuck. After some struggling, I managed to find it out. Now I want to share it with you.
What is exclusive menu action? It's a menu item, when you select it, its friends are deselected. When one of its friends is selected, it gets deselected. It's like a radio button group in a menu.
We're going to use QMenu, QAction and QActionGroup for this purpose.
# assume we are in a QMainWindow method, constructing the menu.
menu = QMenu('Alignment', self.menuBar())
menuGroup = QActionGroup(menu)
menuGroup.setExclusive(True)
left = QAction('left', menuGroup)
center = QAction('center', menuGroup)
right = QAction('right', menuGroup)
actions = (left, center, right)
map(menu.addAction, actions)
map(lambda action: action.setCheckable(True), actions)
center.setChecked(True)
self.menuBar().addMenu(menu)
In this way, you are able to select either left or center or right for alignment submenu.
What is exclusive menu action? It's a menu item, when you select it, its friends are deselected. When one of its friends is selected, it gets deselected. It's like a radio button group in a menu.
We're going to use QMenu, QAction and QActionGroup for this purpose.
# assume we are in a QMainWindow method, constructing the menu.
menu = QMenu('Alignment', self.menuBar())
menuGroup = QActionGroup(menu)
menuGroup.setExclusive(True)
left = QAction('left', menuGroup)
center = QAction('center', menuGroup)
right = QAction('right', menuGroup)
actions = (left, center, right)
map(menu.addAction, actions)
map(lambda action: action.setCheckable(True), actions)
center.setChecked(True)
self.menuBar().addMenu(menu)
In this way, you are able to select either left or center or right for alignment submenu.
Tuesday, June 29, 2010
QGraphicsItem.itemChange event and ItemPositionChange in Qt 4.6
Recently, I had a bug in Robinviz that I could not figure out where it come from. I was drawing a graph and nodes could be moved. Whenever I moved the node, edges connected to it used to come with it to the new position. But after upgrading to Qt 4.6, I saw that edges were not moving.
After some investigation, I realized that QGraphicsItem.itemChange event did not produce QGraphicsItem.ItemPositionChange but only selected, deselected signals. Googling for it, I hardly found that the problem was with the update. Due to performance reasons, Qt developers decided to stop emitting geometrical signals and wanted us to switch it on by supplying a flag for the QGraphicsItem:
You can do this flag option in your constructor. I used try/except because I didn't know what might happen in 4.5 as there was no flag called ItemSendsGeometryChanges. In some other websites, following flag was suggested but it did not work for me:
For those who might be interested how I used itemChanged, I'll provide a portion of my code:
After some investigation, I realized that QGraphicsItem.itemChange event did not produce QGraphicsItem.ItemPositionChange but only selected, deselected signals. Googling for it, I hardly found that the problem was with the update. Due to performance reasons, Qt developers decided to stop emitting geometrical signals and wanted us to switch it on by supplying a flag for the QGraphicsItem:
try:
# available only in Qt 4.6
self.setFlag( QGraphicsItem.ItemSendsGeometryChanges)
except:
# no need to do this in Qt 4.5
pass
You can do this flag option in your constructor. I used try/except because I didn't know what might happen in 4.5 as there was no flag called ItemSendsGeometryChanges. In some other websites, following flag was suggested but it did not work for me:
self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges, True)
For those who might be interested how I used itemChanged, I'll provide a portion of my code:
def itemChange(self, change, value):
if change == QGraphicsItem.ItemPositionChange:
self.updateEdges()
return QVariant(value)
Subscribe to:
Posts (Atom)