×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Thumbs up Threading problem

    Hi!

    I am having a very queer problem with threading and using a particular library. The final application is simple - when the library function is called, perform some other tasks simultaneously.

    Here is an initial code I wrote to check that threading was all ok -
    Code:
    import thread
    import e32
    flag = 1
    s = "Hi!!!"
    def d():
    	e32.ao_sleep(3)
    	return "Hello"
    
    def decode():
    	global s
    	print s
    	s = d()
    	print s
    	global flag
    	flag = 0
    
    def main():
    	global flag
    	flag = 1
    	i = 0
    	thread.start_new_thread(decode,())
    	while (flag):
    		print i,flag
    		i = i+1
    		e32.ao_sleep(0.01)
    	print s
    main()
    Tha above works perfectly fine. When the function is called, I get the output of the while loop, that shows me a stream of numbers. All is fine.

    However, when I try the same thing with an external library -
    Code:
    import thread
    import e32
    import ext_lib
    flag = 1
    s = "Hi!!!"
    def decode():
    	global s
    	print s
    	s = ext_lib.d()
    	print s
    	global flag
    	flag = 0
    
    def main():
    	global flag
    	flag = 1
    	i = 0
    	thread.start_new_thread(decode,())
    	while (flag):
    		print i,flag
    		i = i+1
    		e32.ao_sleep(0.01)
    	print s
    main()
    The phone appears to hang! The only output I got was the following -
    1 0
    1 1
    Could the external function be eating up on so much of the resources (processor) that the other threads are unable to run? But if this is so, isn't the whole point of threading lost?

    Thanks
    Last edited by kedarm; 2009-11-19 at 05:11.

  2. #2
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Threading problem

    Let me rephrase the questions...

    If I have two threads, and one might be very processor intensive, is there some way to ensure that both threads get equal priority?

    In my code, I think the thread involving the external function requires a lot of processor resource. However, the other thread (which is the while loop) takes too much of the processor resource, not allowing the other function to perform.

    Is there any way to ensure that both processes get equal priority? It is not available in Python, but I'm hoping there is something for Python for Symbian.

    Thanks
    Kedar

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    Re: Threading problem


  4. #4
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Threading problem

    Quote Originally Posted by rim_1910 View Post
    Yes, the python s60 shell has an old problem when using multithreading. Recreate your module or generate your own sis.

  5. #5
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Threading problem

    Quote Originally Posted by marcelobarrosalmeida View Post
    Yes, the python s60 shell has an old problem when using multithreading. Recreate your module or generate your own sis.
    What will recreating the module or my own sis do?

    I had created the external library myself and am trying to use it in a thread. The external library performs some image processing on a captured image.

    The code is supposed to start the function in a thread and in the main segment of the program, runs a progress bar. However, the behavior is very erratic - the progress bar starts but the external function takes forever to work, etc.

  6. #6
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Threading problem

    Hi Kedarm !

    [QUOTE=kedarm;683073]What will recreating the module or my own sis do?
    /QUOTE]

    If you have already your app as a sis file you don't need to recreate the shell (use pycore, the default mode). If you are running from shell, you will need. The link for maemo repository explains what it is necessary to do.

    I wrote a multithread code some weeks ago, with queues. Using queues it was possible to show a simple/efficient way to exchange data between treads. If you want see it, the link is here.

    I hope it helps. See you!

Similar Threads

  1. problem in threading
    By kumar_a in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2008-11-12, 09:49
  2. Problem in threading operation...
    By krmlkr in forum Mobile Java General
    Replies: 5
    Last Post: 2008-05-28, 10:20
  3. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  4. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  5. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

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