How to calculate speed of a motor using python and beagle board

Hello I am trying to calculate the speed of the motor by calculating the number of rising edges the encoder of my motor sends to beagle . It sends approximately 400 rising edges(according to data sheet) for one rotation, on counting the number of rising edges i understand how many rotations are done and then i divide it by time so as to get the speed. I wrote a program in python to get the count using threads one thread was used for seeing whether the rising edge occurred on GPIO and the other to increment the count. Now each time I run this for 10 rotations i get the count of around 2000-2700 for the expected count of around 4000

So can anybody help me with this?? Is this the expected output??
And also can anybody suggest a better method to calculate speed of the motor??

Use the eQEP driver. Here is a python binding for the same. Manually reading the GPIO is inviting trouble (+ python threads are not really parallel thanks to GIL).