I wanted to run a certain function as a thread, but I get
SyntaxError: non-keyword arg after keyword arg
And I do not understand why :
#!/usr/bin/env python
import sys
import arduinoReadThread
import arduinoWriteThread
import socket
import thread
bolt = 0
socketArray=list()
HOST ="localhost"
PORT1 =50000
PORT2 =50001
def readAndParseArgv():
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM ) #create an INET, STREAMing socket
s.bind((HOST,PORT1)) #bind to that port
print "test"
s.listen(2) #listen for user input and accept 1 connection at a time.
socketArray.append(s)
s2=socket.socket(socket.AF_INET, socket.SOCK_STREAM ) #create an INET, STREAMing socket
s2.bind((HOST,PORT2)) #bind to that port
print "test"
s2.listen(2) #listen for user input and accept 1 connection at a time.
socketArray.append(s2)
def socketFunctionWrite1():
print threadName
client, address = s1.accept()
while(bolt == 0):
print "Writing connections"
if len(s1ToWriteList) > 0:
client.send(s1ToWriteList.pop(0))
def socketFunctionRead1():
client, address = s2.accept()
while(bolt == 0):
f = client.recv(1024)
print "reading connection"
s1ToWriteList.append(f)
print len(s1ToWriteList)
def socketFunctionWrite2():
client, address = s2.accept()
while(bolt == 0):
print "Writing connections"
if len(s2ToWriteList) > 0:
client.send(s2ToWriteList.pop(0))
def socketFunctionRead2():
client, address = s1.accept()
while(bolt == 0):
f = client.recv(1024)
print "reading connection"
s2ToWriteList.append(f)
print len(s2ToWriteList)
def shutDown():
test = raw_input("Quit ?")
if(test =="y"):
bolt = 1
else:
shutDown()
thread.start_new_thread(target=socketFunctionRead1,())
thread.start_new_thread(target=socketFunctionWrite1,())
thread.start_new_thread(target=socketFunctionRead2,())
thread.start_new_thread(target=socketFunctionWrite2,())
readAndParseArgv()
spreadSockets()
I want to open these sockets as threads. I do not get why I get the non-keyword error, as the function I want to run as a thread is socketFunctionRead1
error :
File "pythonbis.py", line 79
thread.start_new_thread(target=socketFunctionRead1,())
SyntaxError: non-keyword arg after keyword arg
The docs say the the signature for the
thread.start_new_threadcall is:The way you are calling it is:
As you can see you are passing a named (keyword) argument before the non-named one: you are saying
target=socket...before().EDIT: just to clarify. The solution is either to remove the keyword to the first argument or to add it to the second.
HTH!