I am getting an error in a program which is using threading to perform functions simultaneously, this process is a job which is run once per hour, The data that comes in is from a view in sql.
The function that is called in target arg returns a dictionary and says "dict object is not callable". Inside the function, is returned a dictionary. My doubt is what should return in this function, if I don't return anything will it affect any other thread?
# inside the jobs in django I call this function
def ticket_booking():
query = " SELECT * FROM vw_ticket_list;"
ttd = []
try:
result = query_to_dicts(query)
tickets = json.loads(to_json(result))
if tickets:
# Calling the vaccination push message (php).
for ticket in tickets:
# Getting Generic details used by all categories
full_name = tickets['full_name']
gender = tickets['gender']
email =tickets[email]
if tickets['language_id'] == 1: # book english movie tickets
# Calling the function inside the Thread for a Syncronuz Call (Wait and Watch)
myThread = threading.Thread(target=book_english(email, full_name))
myThread.start()
myThread.join()
if tickets['language_id'] == 2: # book italian movie tickets
myThread = threading.Thread(target=book_italian( email, full_name, gender))
myThread.start() # Starting the Thread
myThread.join() #Will return here if sth is returned
As you can see in code comments, if book italian function returns sth, only then it can return here and I have 5 threads in total to excute simultaneously, book italian function is like:
def book_italian(email,fullname,gender):
try
# posts data to another server #
b=requests.post(some postdata)
a =log.objects.create(log data from b in crct format)
return a--->{"Message":"Log created successfully"}
a is type class dict and I tried to change it to many types still gives me same error, this job isn't running when run in crontab.
CodePudding user response:
When you use threading.Thread
to execute something, you should separate the target
callable object (like a function) and corresponding arguments
(parameters) then pass them respectively:
myThread = threading.Thread(target=book_italian, args=(email, full_name, gender))
Refer to document.