Lab3 - Part 4.1

Lab3 - Part 4.1

by Olivier Cloux -
Number of replies: 3

Hi,

I have (had?) a problem with the multicast receiving.

My code works flawlessly in the VM. But when I send it to the submission, I get 0 points.

After close inspection of my logs, it appears my code... does nothing. no print, no output. For reference, my code looks like that


import things
print("Code started")
#some python magic about sockets
while True:
    data = sock.recv(1024)
    print(data)
Not even the first print is displayed. And when I remove the while loop entirely, everything else is printed.

BUT, fun things: if I modify the while loop like that:

try:
    i = 5
    while i > 0:
        data = sock.recv(1024)
        print(data)
        i -= 1
except KeyboardInterrupt:
    pass

Then suddenly I get full grade, everything prints. What's the problem? There was no specification about only doing a fixed number of receives, or catching the KeybordInterrupt. Am I missing something?

In reply to Olivier Cloux

Re: Lab3 - Part 4.1

by Alaeddine El Fawal -

Hi,


The good thing is that you got the full grade... from the comparison of both code snippets, I cannot say anything... may be you did something that solved the problem without paying attention...


Best,

Alaeddine 

In reply to Olivier Cloux

Re: Lab3 - Part 4.1

by Thomas Jacques Alexandre Rivasseau -

To second Olivier's point, we were stuck on the issue for quite some time and replaced:

while True:
message = sock.recv(1024).decode()
print(message[6:])

with his code:
try:
i = 5
while i > 0:
data = sock.recv(1024)
print(data)
i -= 1
except KeyboardInterrupt:
pass
and went from 0/3 to 3/3.

This seems like a glitch and maybe it could be a good idea to warn students in some way? (we didn't get a chance to check but our guess is that maybe a keyboardInterrupt is launched during testing?)

Thanks olivier for raising the question :)))

In reply to Thomas Jacques Alexandre Rivasseau

Re: Lab3 - Part 4.1

by Manuel Leone -

Dear Oliver & Thomas, 

there's no reason to do such a fancy thing (even if it works) to get your log printed.

Whenever you get a 0 score in any test of the grading system, a help message is printed stating (copy-pasted from the website):

"IMPORTANT:
- If your logs in the 'output' folder are an empty file, then you can change your print(message) statements by
print(message, flush=True) and this should solve the issue."

I bet that's sufficient to get 3/3 for both your cases. 

For completeness, the reason why this happens is that we kill your code after a defined timeout, otherwise all of your while True will stay there forever hanging the server :D.

Best,

Manuel