Receive Message

The receive_message function pauses the Python process and waits until a message is received over the network. The function definition is:

def receive_message():

This function returns the received message (type is dictionary).

For example, suppose we called

message = receive_message()

Then Python is going to update the LWOS Python state as follows:

  • Hostname: "b.com"
  • Python
    • Status: "BLOCKED",
    • System Call
      • Type: "NETWORK"
      • Mode: "READ"
      • Hostname: null
      • Data: null
    • Values Stack:
      • [ ]
      • [ ]
    • Expression Stack:
      • [ ]
      • receive_message()

Python -> Status is now "BLOCKED." This prompts LWOS to inspect Python -> System Call. When Python -> System Call -> Type is "NETWORK" and Mode is "READ," LWOS updates Status to "WAITING_ON_NETWORK." The computer then sits idle until it receives a message.

Suppose that at some point, the connected network device updates the Network property and interrupts b.com as follows:

  • Hostname: "b.com"
  • Status: "WAITING_ON_NETWORK"
  • Interrupts:
    • Network: true
  • Command: "python"
  • Network
    • Hostname: "a.com"
    • Data: "GET /articles/Best_Gadgets HTTP/1.1"
    • Signal: false

LWOS received a message from a.com. When command is python and the Status is "WAITING_ON_NETWORK," LWOS copies Network -> Hostname to Python -> System Call -> Hostname and Network -> Data to Python -> System Call -> Data. LWOS then resumes the Python process by updating Python -> Status to "SYSCALL_COMPLETE." Here is the updated LWOS Python state:

  • Python
    • Status: "SYSCALL_COMPLETE"
    • System Call
      • Type: "NETWORK"
      • Mode: "READ",
      • Hostname: "a.com"
      • Data: "GET /articles/Best_Gadgets HTTP/1.1"
    • Values Stack:
      • [ ]
      • [ ]
    • Expression Stack:
      • [ ]
      • receive_message()

Python then constructs the following Python dictionary object from the received data:

  • hostname: "a.com"
  • message: "GET /articles/Best_Gadgets HTTP/1.1"

Python appends the new dictionary to the Object Store and pushes the reference to this object to the Values Stack. Here is the updated python state:

  • Python
    • Status: "SYSCALL_COMPLETE"
    • Values Stack:
      • Python reference 0
    • Expression Stack:
      • [ ]
    • Object Store:
      • 0
        • hostname: "a.com"
        • message: "GET /articles/Best_Gadgets HTTP/1.1"

The receive_message function call is now complete. Python then pops the top of the Values Stack and stores the popped element (Python reference 0) in a new variable message as follows:

  • Python
    • Status: "RUNNING"
    • Variables:
      • entry message: Python reference 0
Quiz (1 point)

Please write a Python statement that asks LWOS to wait for a network request and stores the request in the variable called data.

Become a subscriber to save your progress, see the correct answer, and more!
Quiz (1 point)

Please fill in the blank.

When executing the receive_message function, python sets Python -> System Call -> Type to _________

Become a subscriber to save your progress, see the correct answer, and more!
Quiz (1 point)

Please fill in the blank.

After LWOS receives a message from the network device, it will copy the sender's hostname to Python -> System Call -> _______

Become a subscriber to save your progress, see the correct answer, and more!
Quiz (1 point)

Please fill in the blank.

Python stores the request information in a ________ object (enter the object type).

Become a subscriber to save your progress, see the correct answer, and more!

Comments

Please log in to add comments