You Are Here:

Community: Developer Discussion Boards

#1 Old Understanding Threads - 2008-12-14, 19:46

Join Date: Dec 2008
Posts: 11
Location: Germany
Slowmoe
Offline
Registered User
Hi,

I've got a little problem with threads in Python. Up to now, I only know Threads from Java, but it should be similar in Python.


The following code refreshes an image on the display if the accelerometer gets a specific orientation event! That works fine.

Additionally it should now play a specific mp3 for a specific orientation event (parallel/synchronized to refreshing the image). I tried to realize this by the code marked in red!

Code:
...
args = "", ""
soundFB = thread

def paintScreen(range, source):
    canvas.blit(source)

def playSound(empty1, empty2):
    input = UpSound
    input.set_volume(2)
    input.play(times=1, interval=0, callback=None)
    input.stop()

def print_orientation(orientation_value):
    #print >> to_peer, orientations[orientation_value]
    if orientations[orientation_value] == 'Up':
        paintScreen((), UpImage)
        soundFB.start_new_thread(playSound, args)
...
Assumed that print_orientation() is allready called:

The "playSound" method seems to start, the image becomes refreshed, but no sound is played and then the whole application freezes.

(the playSound method on it's own works fine! It's just the combination with the thread!)

Can anybody give me an advise how to handle this problem?
Reply With Quote

#2 Old Unhappy Re: Understanding Threads - 2008-12-14, 20:36

Join Date: Jan 2004
Posts: 369
Location: Helsinki
Send a message via Skype™ to miohtama
miohtama's Avatar
miohtama
Offline
Regular Contributor
Quote:
Originally Posted by Slowmoe View Post
Hi,

I've got a little problem with threads in Python. Up to now, I only know Threads from Java, but it should be similar in Python.
Since you didn't post full source code a precise answer is impossible to give.

Threads on Python mostly work fine - like threads on Java. But threads on Symbian are f*cked up. Namely, you cannot share native objects across the threads (files, sockets). This is due to limitations in Symbian "server" architecture. Usual symptoms are untraceable lock ups or application crashes. Also, some functions are callable on the main thread only.

Internally PyS60 maps threads to Symbian Active Objects - read more about architectural limitations here - article about Microsoft trying port .NET framework on Symbian: http://www.jot.fm/issues/issue_2006_04/article4/

1. Try create all objects in the same thread they are accessed.

2. See multithread debugging/exception tracing tips from this example app:

http://bazaar.launchpad.net/~pys60co...7in81mt9gmhv-6


Mikko Ohtamaa
Twinapex Research
http://www.twinapex.com
Reply With Quote

#3 Old Re: Understanding Threads - 2008-12-17, 13:36

Join Date: Dec 2008
Posts: 11
Location: Germany
Slowmoe
Offline
Registered User
Hi,

up to now my application runs stable (including the audio thread), but one thing is mysterious.

The "playSound" method runs in a thread without exceptions, the audio states are correct and the sound is played, but I can't hear the sound!


I've checked my mobile phone profile ("general") two times.

Is it generally impossible to run the audio module in a thread?!?!

With a normal call (without thread) the same method runs well and I can hear the sound.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between handling HTTP session in threads and without threads LavanyaSpm General Symbian C++ 0 2008-09-22 12:37
Porting to Symbian: threads, timers, active objects problem thanhtranhd General Symbian C++ 3 2008-02-01 00:54
Threads List in an application mailkamlesh General Symbian C++ 1 2007-11-26 09:07
Message to everybody - STOP USING THREADS hotcheese General Symbian C++ 8 2007-03-05 13:18
mixing AO, threads and sockets mikfi Symbian Networking & Messaging 6 2006-11-22 00:19

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia