You Are Here:

Community: Developer Discussion Boards

#1 Old Thead and key - 2006-06-13, 23:08

Join Date: Jun 2006
Posts: 14
Cyxapeff
Offline
Registered User
Hi all!
Sorry I very bad speek english (i am from russia). I have problem. Please help my. I try use thead in my script, but when i use Keyboard class my script and smart... hm... droop... i don't know how it is in english )
hm... say smart don't work. before restart.
Keyboard class i get from ball.

Done. I have solution.
Last edited by Cyxapeff : 2006-06-15 at 15:17.
Reply With Quote

#2 Old Re: Thead and key - 2006-06-15, 15:31

Join Date: Jun 2006
Posts: 14
Cyxapeff
Offline
Registered User
I have problem again.

I write irc client. Code part:

Code:
	def connect(self): #this work
		thread.start_new_thread(self.connect_bg,())
		self.run=True
		
		while self.run==True:
			self.print_text()
			e32.ao_sleep(0.1)

	def connect_bg(self): #this work to!
		self.read=1
		self.hello=0
		self.users_run=0
		self.pref_run=0
		self.run=1
		self.F.write(u"!!!Connect \n")
		self.read=1
		appuifw.app.menu = [(u"Выход", self.exit)]		
		i=0		
		self.echo("open socket...","system")
		print u"open socket.."
		self.s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
		self.echo("try connect...","system")
		print u"try connect"
		addr=(self.config['host'],self.config['port'])
		self.s.connect(addr)
		self.echo("connected.","system")
[skip connect command to server]
		self.echo("OK! Server (please wait...):","system")
		appuifw.app.menu = [(u"Отправить", self.send_msg), (u"Юзеры", self.users), (u"Скриншот", self.save_screen), (u"Выход", self.exit)]
		self.listen=1
		thread.start_new_thread(self.keys,())
		self.echo("start listen","system")
		self.chat()

	def chat(self): #this NOT work (((	
		self.read=1
		self.hello=0
		self.users_run=0
		self.pref_run=0

		while self.run==True:
			data = self.readline(self.s)
			part=re.split(":",data)
			part1=re.split(" ",part[1])
			self.F.write(">"+data+"\n")
			if part[0]=="PING ":
				print u"< pong"
				#self.text.append("< PONG :"+part[1]+"\n")
				self.s.send("PONG :"+part[1]+"\n")
				#self.F.write(u"< pong"+part[1]+"\n")
			elif part1[1]=="353":
				self.users=re.split(" ", part[2])
			elif part1[1]=="PRIVMSG" and part1[2]==self.config['chanal']:
				nick=re.split("~",part[1])
				print u"> "+unicode(nick[0], self.config['encoding'])+": "+unicode(part[2], self.config['encoding'])
				self.echo("> "+nick[0]+": "+part[2],"chat")
			elif part1[1]=="PRIVMSG" and part1[2]==self.config['nick']:
				nick=re.split("~",part[1])
				print u"> "+unicode(nick[0], self.config['encoding'])+": "+unicode(part[2], self.config['encoding'])
				self.echo("> "+nick[0]+": "+part[2],"in_privat")
			else:
				print u"> "+unicode(data, self.config['encoding'])
				self.echo("> "+data,"system")	

	def readline(self,z):
		s=[]
		while 1:			
			c=z.recv(1)
			s.append(c)
			if c=='\n':
				break
		return ''.join(s)[:-2]
I try connect to lem.freenode.net. When script get "Current global users: 26511 Max: 31437 " (this do chat() function), GPRS disconnect. If I not use thead, all ok! But I must use thead.... Why disconnect?

P.S May be I should publish other functions? Say me what you need.
P.P.S Sorry for my english again...
Last edited by Cyxapeff : 2006-06-15 at 17:24.
Reply With Quote

#3 Old Re: Thead and key - 2006-06-15, 18:29

Join Date: Aug 2004
Posts: 290
simo.salminen
Offline
Regular Contributor
Few things:
- you cannot use many pys60 objects between different threads. For example, you can only access UI stuff from the main thread.
- implement proper logging module, and pin-point the problem. more detailed problem description is needed
- please, try to improve your english!

Try to add more print statements to your code. If you start another thread, use this kind of code to catch errors from it:

Code:
def other_thread():
 try:
   <code>
 except:
   import traceback
   traceback.print_exc()
You can also use this module to log errors to file:
http://discussion.forum.nokia.com/fo...10&postcount=3
Reply With Quote

#4 Old Re: Thead and key - 2006-06-15, 19:53

Join Date: Jun 2006
Posts: 14
Cyxapeff
Offline
Registered User
Quote:
Originally Posted by simo.salminen
Few things:
- you cannot use many pys60 objects between different threads. For example, you can only access UI stuff from the main thread.
where I can read about this limitations?
Quote:
Originally Posted by simo.salminen
- implement proper logging module, and pin-point the problem. more detailed problem description is needed
Hm. Your logging module not give me traceback... May be I don't something right? Full script: http://webfile.ru/991701. More detailed problem description: Script connected to server, get data. connect_bg() done. chat() execute cycle 4 time and gprs disconnect. If push exit button, exit successfully. You try use script in your phone. Script need cp1251 encoding from computer python.
Quote:
Originally Posted by simo.salminen
- please, try to improve your english!
I learn english now...

Quote:
Originally Posted by simo.salminen
Try to add more print statements to your code. If you start another thread, use this kind of code to catch errors from it:

Code:
def other_thread():
 try:
   <code>
 except:
   import traceback
   traceback.print_exc()
You can also use this module to log errors to file:
http://discussion.forum.nokia.com/fo...10&postcount=3
Reply With Quote

#5 Old Re: Thead and key - 2006-06-15, 22:36

Join Date: Jun 2006
Posts: 14
Cyxapeff
Offline
Registered User
Heh! I comment print and write log functions and script is work!

mla.... Now don't work send function ((. Must think....
Last edited by Cyxapeff : 2006-06-15 at 23:21.
Reply With Quote

#6 Old Re: Thead and key - 2006-06-17, 02:06

Join Date: Aug 2004
Posts: 290
simo.salminen
Offline
Regular Contributor
Quote:
Originally Posted by Cyxapeff
where I can read about this limitations?
It is mentioned in the documentation .pdf.
Reply With Quote

#7 Old Re: Thead and key - 2006-06-17, 10:16

Join Date: Jun 2006
Posts: 14
Cyxapeff
Offline
Registered User
Quote:
Originally Posted by simo.salminen
It is mentioned in the documentation .pdf.
oh. yes. I am not attentive. (
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
keypress thead priority qqsg2004 Mobile Java General 0 2004-08-25 04:27

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