LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-30-2014, 03:16 AM   #1
golden_boy615
Member
 
Registered: Dec 2008
Distribution: Ubuntu Fedora
Posts: 445

Rep: Reputation: 18
python: why threading.thread pass empty dictionary to function thread


Hi
I would like to send a dictionary to a thread at the begining of its creation.part of my code that relates to my problem is as follow (this code tries to map a websocket to a another none web-socket):
Code:
class SimpleEcho(WebSocket):
     def SockFun(self,**FlagDict):
         try:    
             print "6"
             ms=mysocket()
             print "7"
             ms.connect("127.0.0.1",7778)
             print "8"
             while (1):
                 print FlagDict
                 print "9"
                 FlagDict["sockexists"]=1
                 print "90"
                 #data=FlagDict["Data"]
                 msg=str(self.data)
                 self.data=''
                 print "91"
                 #FlagDict["Data"]=''
                 print "92"
                 #msg=str(self.data)
                 print msg
                 print "93"
                 #print self.FlagDict
                 ms.mysend(msg)
                 print "10"
                 a=ms.myreceive()
                 print "11"
                 self.sendMessage(a)
                 print "12"
             FlagDict["sockexists"]=0
             print "13"
             FlagDict["threadexists"]=0
             ms.myclose()
             print "14"
         except Exception as a:
             FlagDict["sockexists"]=0
             FlagDict["threadexists"]=0
             ms.myclose()
             print "error in SockFun",a
 
 
     def handleMessage(self):
         print "2"
         if self.data is None:
             print "3"
             self.data = ''
         else:
             self.FlagDict["Data"]=self.data
             self.CheckThread()
             print "20"

class WebSocket(threading.Thread):
     def __init__(self, server, sock, address):
         self.server = server
         self.client = sock
         self.address = address
     
         self.handshaked = False
         self.headerbuffer = ''
         self.readdraftkey = False
         self.draftkey = ''
         self.headertoread = 2048
         self.hixie76 = False
         
         self.fin = 0
         self.data = None
         self.opcode = 0
         self.hasmask = 0
         self.maskarray = None
         self.length = 0
         self.lengtharray = None
         self.index = 0
         self.request = None
         self.usingssl = False
         
         self.state = self.HEADERB1
         
         # restrict the size of header and payload for security reasons
         self.maxheader = 65536
         self.maxpayload = 4194304
         self.FlagDict={}
         self.FlagDict["sockexists"]=0
         self.FlagDict["threadexists"]=0
     def CheckThread(self):
             self.FlagDict["Data"]=self.data
             print self.FlagDict
             try:
                 print "4" 
                 if self.FlagDict["threadexists"]==0:
                     print "5"
                     self.FlagDict["threadexists"]=1
                     print "15"
                     ts=threading.Thread(target=self.SockFun(),args=self.FlagDict)
 #                    ts=threading.Thread(target=self.SockFun())
                     print "16"
                     ts.deamon=True
                     print "17"
                     ts.start
                     print "18"
                 print "19"
             except Exception as d:
                 print "error in handleMessage",d
                 print "202"
code output at runtime is as follows:
Quote:
('127.0.0.1', 51180) connected
1
2
{'Data': bytearray(b'Page-1;'), 'sockexists': 0, 'threadexists': 0}
4
5
15
6
7
8
{}
9
90
91
92
Page-1;
93
10
11
12
{'sockexists': 1}
9
90
91
92

93
10
11
12
{'sockexists': 1}
9
90
91
92

93
10
11
12
{'sockexists': 1}
9
90
91
92

93
10
11
12
{'sockexists': 1}
9
90
91
92

93
10
11
12
{'sockexists': 1}
9
90
91
92

93
10
as you can see threading.thread pass empty dictionary to SockFun function. why this is happened and how can I solve it?
fore more info about WebSocket module you can see:
https://github.com/opiate/SimpleWebSocketServer
http://opiate.github.io/SimpleWebSocketServer/
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread spawning with the same function jayadhanesh Linux - Newbie 5 02-10-2014 01:11 AM
[SOLVED] How to pass Resultset rs object as parameter to Thread snehal89 Linux - Software 1 04-20-2013 09:57 AM
python thread safety: printing from thread to redirected stdout - safe? BrianK Programming 2 10-11-2010 11:28 AM
how to change and pass thread parameter back to main dragondad Programming 3 09-19-2005 01:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration