Skip to main content
14 events
when toggle format what by license comment
Aug 16, 2020 at 14:45 comment added Shredderroy Thank you so much again! Yes, I was testing it by using Pause[60 * 15] in WL, and ensuring that when the programme resumed, the TCP server still returned the results. I need a long-running server, which I intend to call over the course of the generations of my evolutionary algorithm. The complete programme takes over eight hours to run, so I definitely need the server to accept requests after considerable delays.
Aug 16, 2020 at 14:39 history edited flinty CC BY-SA 4.0
fix timeout issues - there is now no timeout at all on the socket
Aug 16, 2020 at 14:37 comment added flinty @Shredderroy I've removed the timeout completely - it should stay up indefinitely until the connection is closed even with considerable delay in between sending.
Aug 16, 2020 at 14:33 history edited flinty CC BY-SA 4.0
fix timeout issues - there is now no timeout at all on the socket
Aug 16, 2020 at 14:00 history edited flinty CC BY-SA 4.0
timeout fixes
Aug 16, 2020 at 13:48 comment added flinty @Shredderroy Ah, in that case there's still something wrong with my code then, because the time delay is arbitrary. If recv gets no data in the time frame then it raises an exception and this finishes off the connection. Have a look at this answer stackoverflow.com/a/16745561 . I'll see if I can modify the server code to fix this for arbitrary timeout. It also looks like serve_forever timeout anyway stackoverflow.com/a/27830693 so if you don't handle the whole request quickly enough and your second Map is issued too late, the connection breaks down.
Aug 16, 2020 at 13:41 comment added Shredderroy Thanks so much again. You know what made the difference? I was using time.sleep(0.05). Then I changed it to time.sleep(0.06), and now all the various maps get evaluated correctly.
Aug 16, 2020 at 12:27 comment added flinty @Shredderroy Strange - maybe there is still a race of some kind. It works for me if I do sock = SocketConnect[...] followed by many maps followed by Close[sock]; I even tried with a Do loop instead of a single Map: vals = Reap[Do[Sow[Map[getResFromPython[sock], {"arg1", "arg2", "arg3"}]],10]][[-1, 1]] and this produces 30 results in python and 10 lists of {"{\"res\": 1}", "{\"res\": 1}", "{\"res\": 1}"} in mathematica. Are you sure you cleared out all old definitions and copied the above code correctly for both server and Mathematica ?
Aug 16, 2020 at 2:20 comment added Shredderroy Another quick question. When I try to evaluate two Maps, the second one never gets evaluated. vals1 = Map[getResFromPython[sock], {"arg1", "arg2", "arg3"}]; vals2 = Map[getResFromPython[sock], {"arg11", "arg12", "arg13"}]; The first one gives me the correct results, but the second one never seems to reach the server,
Aug 16, 2020 at 1:50 vote accept Shredderroy
Aug 16, 2020 at 1:50 comment added Shredderroy You, sir, are a genius! Thank you for that detailed and painstaking response!
Aug 15, 2020 at 23:37 history edited flinty CC BY-SA 4.0
edited body
Aug 15, 2020 at 22:48 history edited flinty CC BY-SA 4.0
deleted 8 characters in body
Aug 15, 2020 at 22:41 history answered flinty CC BY-SA 4.0