maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   little help understand python + dbus loop + sleep (https://talk.maemo.org/showthread.php?t=66482)

colchaodemola 2010-12-03 01:32

little help understand python + dbus loop + sleep
 
Hi , i am trying to learn dbus to make a few changes to the call proccess but i am facing a problem that i can not understand.

Here is a very simple example of a python code that SHOULD reject a call with their respective output.
Code:

import gobject
import dbus
import time
import datetime
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

bus = dbus.SystemBus()
sbus = dbus.SessionBus()

def disconnect():
        print 'Running disconnect() at' + str(datetime.datetime.now())
        callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
        smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
        print smsiface.Release()

def callDetected(state):
        print 'callDetected() at' +  str(datetime.datetime.now())
        disconnect()

sbus.add_signal_receiver(callDetected,dbus_interface="org.freedesktop.Telepathy.Connection.Interface.Requests",signal_name="NewChannels")
gobject.MainLoop().run()

When the signal NewChannels is received the callDetected function is executed and then execute the disconnect() method.
Since, i believe, the call is not fully established release will execute but not drop the call. Here is the output...

callDetected() at2010-12-02 22:30:23.555880
Running disconnect() at2010-12-02 22:30:23.557619

The disconnect was executed almost at the same time frame that callDetected() like i expect.


Now, i added a delay before execute the disconnect() method to give time to the connection be really made so i would expect the connection be dropped just fine.


Code:

import gobject
import dbus
import time
import datetime
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

bus = dbus.SystemBus()
sbus = dbus.SessionBus()

def disconnect():
        print 'Running disconnect() at' + str(datetime.datetime.now())
        callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
        smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
        print smsiface.Release()

def callDetected(state):
        print 'callDetected() at' +  str(datetime.datetime.now())
        time.sleep(1)
        disconnect()

sbus.add_signal_receiver(callDetected,dbus_interface="org.freedesktop.Telepathy.Connection.Interface.Requests",signal_name="NewChannels")
gobject.MainLoop().run()

The problem is that the disconnect is being run almost ten seconds after the first output line.

callDetected() at2010-12-02 22:33:13.602907
Running disconnect() at2010-12-02 22:33:22.481692


Why if i put it to sleep 1 second, the delay is over 11 seconds ?

One thing i have noticed is that during these 11 seconds i can not even type in the ssh shell, it is like the phone is too busy ... though the UI is answering just fine.

Creamy Goodness 2010-12-03 04:13

Re: little help understand python + dbus loop + sleep
 
i would try to disable the cpu scheduler with the instructions here:
http://talk.maemo.org/showthread.php?t=47479
sleep commands usually put threads to sleep for a minimum amount of time, and it's usually going to sleep for longer than you specify. if the cpu scheduler decides the incoming call is important, it might ignore your thread for a while. i dunno. maybe you have some other error but i don't know python :)

jstokes 2010-12-03 07:46

Re: little help understand python + dbus loop + sleep
 
Quote:

Originally Posted by colchaodemola (Post 888057)
One thing i have noticed is that during these 11 seconds i can not even type in the ssh shell, it is like the phone is too busy ... though the UI is answering just fine.

http://www.pygtk.org/pygtk2reference...t--timeout-add

If gobject.timeout_add_seconds is available, you may prefer to use that instead.

colchaodemola 2010-12-03 13:27

Re: little help understand python + dbus loop + sleep
 
disable cgroups make the application works fine ...
Is there any colateral effect doing this ?

salatiel 2010-12-06 10:18

Re: little help understand python + dbus loop + sleep
 
You will notice phone app may lag on heavy load and you will miss calls.


All times are GMT. The time now is 19:43.

vBulletin® Version 3.8.8