Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you explain this python code, what is the number (100000000) in the while loop , what this code does etc., something to understand what

Can you explain this python code, what is the number (100000000) in the while loop , what this code does etc., something to understand what is going on

Mini Elevator (prototype) controller project, with stepper motor running on raspberry pi.

Threading

import threading, Queue

def func1(num, q):

while num < 100000000:

num = num**2

q.put(num)

def func2(num, q):

while num < 100000000:

num = q.get()

print num,

num = 2

q = Queue.Queue()

thread1 = threading.Thread(target=func1,args=(num,q))

thread2 = threading.Thread(target=func2,args=(num,q))

print 'setup'

thread1.start()

thread2.start()

printing

=== pu@pumbair:~/StackOverflow:507 > ./tst.py

setup

4 16 256 65536 4294967296

ThreadedUDPListener.py

#import socket

import threading

import time

FloorStopList = [0,0,0,0,0,0]

# from udpreceive import *

from UDPListenerClass import UDPListenerClass

def main():

c = UDPListenerClass(FloorStopList)

print (c.startthread())

while True:

print ("main:" , FloorStopList)

time.sleep(2)

#ListenerThread.shutdown()

#ListenerThread.server_close()

#c.startthread

#print (FloorStopList)

#print ('Main: starting thread')

#ListenerThread = threading.Thread(target=c.udpreceive())

#ListenerThread.daemon = True

#ListenerThread.start()

main()

#print(ListenerThread.isAlive)

#print("Main: Thread has started")

UDPListenerClass.py

import threading

class UDPListenerClass(threading.Thread):

def __init__(self.FSL):

self.FloorStopList=FSL

def startthread(self):

print("thread: Thread starting")

ListenerThread = threading.Thread(target=self.udpreceive())

ListenerThread.daemon = True

ListenerThread.start()

print ("Thread: Thread has started")

print ('Thread: ' ,self.FloorStopList)

return 'Thread: started'

def udpreceive(self):

import socket

UDP_IP = "0.0.0.0"

UDP_PORT = 2018

sock = socket.socket(socket.AF_INET, # Internet

socket.SOCK_DGRAM) # UDP

sock.bind((UDP_IP, UDP_PORT))

sock.settimeout(1.0)

c = 0

while True:

try:

data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes

print ("received message: ", data)

print ("Address: ", addr)

x=data.decode('utf-8')

command,key,value = x.split(',')

print (str(command))

print (key)

print ( value)

floor = int(key)

self.FloorStopList[key] = int(value)

print ('Thread: ' , self.FloorStopList)

except socket.timeout:

c += 1

print (c)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago