You Are Here:

Community: Developer Discussion Boards

#1 Old Question How to kill a thread? - 2007-11-27, 21:13

Join Date: Apr 2004
Posts: 107
Send a message via ICQ to carknue
carknue
Offline
Regular Contributor
Hi,

how can I kill a thread that does not respond anymore?

I start the the thread like this:
Code:
thread.start_new_thread(bt_scan,())
Reply With Quote

#2 Old Re: How to kill a thread? - 2007-11-28, 11:11

Join Date: Apr 2007
Posts: 81
Location: Lublin, Poland
janekw_'s Avatar
janekw_
Offline
Regular Contributor
Here's quite a thread about thread: http://discussion.forum.nokia.com/fo...d.php?t=118547
What do you mean by "does not respond"?


whatever happens happens
Reply With Quote

#3 Old Re: How to kill a thread? - 2007-11-28, 21:09

Join Date: Apr 2004
Posts: 107
Send a message via ICQ to carknue
carknue
Offline
Regular Contributor
Ok, I call the finddevices() function from the lightblue module to do a bluetooth scan. Normaly this function delivers after 10-30 sec a list with all found BT devices, but sometimes it does not deliver anything, it just hangs and the thread cannot close automatically.

I thought to ta start the finddevices function in the second thread and wait at least 120 sec and then close the first thread and I thought that with closing the first thread, the second thread would also close but it doesn't. os.getpid() deliverers the same id for each thread, so it could not be killed. How can I kill or abort the hanging thread?

Code:
def bt_mainthread():
	global bt_busy
	thread.start_new_thread(bt_scan,())
	time.sleep(1)
	while bt_busy and (bt_scan_time < 120):
		time.sleep(1)
	if bt_scan_time > 119:
		blues.off()
		time.sleep(5)
		blues.on()
		time.sleep(5)
		bt_busy = False
		
def bt_scan():
	global btscan, btquery_list, bt_busy, bt_scan_time
	bt_busy = True
	bt_scan_time = 0
	try:
		btscan = lightblue.finddevices()
	except:
		btscan = []
	btquery_list = []
	for i in range(len(btscan)):
		btquery_list.append(query_bt(btscan[i]))
	bt_busy = False

def loop():
   global bt_busy, bt_scan_time
   if config['BT_SCAN'] > 0 and not bt_busy:
	bti += 1
	if (bti > config['BT_SCAN']*1) and not bt_busy:
	   bti = 0
	   thread.start_new_thread(bt_mainthread,())

			
   if bt_busy:
	bt_block += 1
	bt_scan_time += 1
Reply With Quote

#4 Old Re: How to kill a thread? - 2008-03-04, 00:54

Join Date: Mar 2007
Posts: 5
phonegnome
Offline
Registered User
Did you come up with a solution to this?
Reply With Quote

#5 Old Re: How to kill a thread? - 2008-03-06, 20:19

Join Date: Jan 2004
Posts: 368
Location: Helsinki
Send a message via Skype™ to miohtama
miohtama's Avatar
miohtama
Offline
Regular Contributor
Quote:
Originally Posted by phonegnome View Post
Did you come up with a solution to this?
PyS60 does not have a function for this. But looks like it's possible on Symbian:

http://www.symbian.com/Developer/tec...ead%3a%3aKill()

So native extension is needed.


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

#6 Old Re: How to kill a thread? - 2008-03-30, 21:05

Join Date: Mar 2007
Posts: 153
novis
Offline
Regular Contributor
Hello,

I have problems killing a thread in python. The whole app. seems to crash.
I tried this:
Code:
import thread

def subthread():
    global bla1, bla2, bla3
    while subthread_active:
        # do something

# start the subthread
subthread_active = True
thread.start_new_thread(subthread, ())

# stop the subthread
subthread_active = False
As a result of "subthread_active = False" the whole application is chrashing.
Reply With Quote

#7 Old Re: How to kill a thread? - 2008-03-30, 23:12

Join Date: Jan 2004
Posts: 368
Location: Helsinki
Send a message via Skype™ to miohtama
miohtama's Avatar
miohtama
Offline
Regular Contributor
Quote:

Code:
def subthread():
    global bla1, bla2, bla3
    while subthread_active:
        # do something

# start the subthread
subthread_active = True
thread.start_new_thread(subthread, ())

# stop the subthread
subthread_active = False
You need to give CPU time to the main thread or the application is stuck in the subthread. Call e32.ao_sleep() or similar in the worker loop. Also, subthread_active must be a global variable.


Mikko Ohtamaa
Twinapex Research
http://www.twinapex.com
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
console app running problem xcompass General Symbian C++ 3 2009-05-08 14:26
S60 SDK 3rd edition FP1 Emulator problem justteam Symbian Tools & SDKs 12 2008-03-04 05:44
Kill Thread Problem westweb General Symbian C++ 0 2007-08-01 19:55
Error on "emulator" zhang2008 General Symbian C++ 2 2006-10-08 17:55
Link errors when trying to Display bitmap Bkc82 Symbian Media (Graphics & Sounds) 1 2006-01-16 23:46

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