Object model subscription - sometimes fails
-
Hello!
I would like to save some parameters during printing. I constantly read object model and save choosed values.
while True: subscribe_connection = SubscribeConnection(SubscriptionMode.PATCH) subscribe_connection.connect() try: object_model = subscribe_connection.get_object_model() finally: subscribe_connection.close() [...] layer_actual = object_model.job.layer
But sometimes python script get stuck:
^CTraceback (most recent call last): File "print_loger.py", line 43, in <module> object_model = subscribe_connection.get_object_model() File "/home/pi/.local/lib/python3.7/site-packages/dsf/connections/subscribe_co nnection.py", line 35, in get_object_model object_model = self.receive(ObjectModel) File "/home/pi/.local/lib/python3.7/site-packages/dsf/connections/base_connect ion.py", line 77, in receive json_string = self.receive_json() File "/home/pi/.local/lib/python3.7/site-packages/dsf/connections/base_connect ion.py", line 108, in receive_json part = self.socket.recv(BUFF_SIZE)
Now I'm working on 3.4.6 version.
What could be the reason of this behavior?
-
@Lem Pressing emergency stop resets DCS and all connected IPC sockets.
-
@chrishamm Ok, but it's hard to recognize when script get stuck. Function get_object_model() don't raise any error... Beside this printing works properly so I wouldn't like to reset printer.
-
@Lem I'm sorry but I confirm that. The original DSF demo application shuts down properly when DCS is terminated on E-STOP. I'd expect the Python library to generate an event/error as well when the socket is closed. @Falcounet can you check this please?
-
@chrishamm @Lem I'm going to look at this
-
@Lem I just releaseed a new version of dsf-python which raises an
dsf.connections.exceptions.IPCSocketBrokenException
exception when the IPC socket is closed.
Please try and report back if you run in other problems. -
I've just implemented checking for an exception. I will let you know about the test results!
-
@Falcounet I think that your solution works - I can't register exception handling but I don't experience so many stucks. Did you improve something more? I will let you know if I am sure. But...
Function again gets stuck for ~3 min and I closed it. Problem appear in connect function this time.DSF 3.4.6 and dsf-python-3.4.6.post4
Error:
-
The problem with get_object_model() has been resolved, but I'm still stuck with connect(). Can you add an exception in this function as well?
-
@Lem said in Object model subscription - sometimes fails:
The problem with get_object_model() has been resolved, but I'm still stuck with connect(). Can you add an exception in this function as well?
Given the traceback above, the socket is waiting to receive data so I guess a timeout is what is needed. Although the socket is currently in blocking mode so setting a timeout won't work.
Are you able to reproduce this problem ?
If so, please post a snippet I can use to try a fix. -
@Falcounet Ok, I try to reproduce error and save snippet but probably I will post the same info like on photo above.
Apart from this, can you tell which way of object model subscription is the best?
Option 1:
if __name__ == "__main__": subscribe_connection = SubscribeConnection(SubscriptionMode.FULL) subscribe_connection.connect() while True: time.sleep(1.0) object_model = subscribe_connection.get_object_model() [...] if script_end == True: subscribe_connection.close()
Option 2:
if __name__ == "__main__": subscribe_connection = SubscribeConnection(SubscriptionMode.FULL) while True: time.sleep(1.0) subscribe_connection.connect() object_model = subscribe_connection.get_object_model() subscribe_connection.close() [...]
Option 3:
if __name__ == "__main__": while True: time.sleep(1.0) subscribe_connection = SubscribeConnection(SubscriptionMode.FULL) subscribe_connection.connect() object_model = subscribe_connection.get_object_model() subscribe_connection.close() [...]