instamatic-dev / instamatic

Python program for automated electron diffraction data collection
https://instamatic.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
58 stars 27 forks source link

Definition of camera.camera_client.CamClient.get_attrs() #36

Closed kttn8769 closed 4 years ago

kttn8769 commented 4 years ago

Hi,

I had a question while I was reading the CamClient class code.

CamClient.init_attr_dict() method is defined as follows,

https://github.com/stefsmeets/instamatic/blob/2be8cdb1e2337b1df437868a8de50878d178bd88/instamatic/camera/camera_client.py#L143-L145

I am curious where get_attrs() method is defined for CamClient class.

stefsmeets commented 4 years ago

Hi @kttn8769,

It's defined here: https://github.com/stefsmeets/instamatic/blob/2be8cdb1e2337b1df437868a8de50878d178bd88/instamatic/server/cam_server.py#L130

It's used for my own implementation of RPC. It's a bit of a hack to enable tab completion IPython when the camera (or tem for that matter) are run in host/server mode.

kttn8769 commented 4 years ago

Thank you @stefsmeets ,

then, CamServer.get_attrs is somehow incorporated into CamClient class?? It is difficult for me to see such interaction in the code...

Sorry if this is a silly question. Maybe I'm overlooking or misunderstand something.

stefsmeets commented 4 years ago

Yeah, it mimicks the attributes from the actual camera interface in CamClient, because it goes over a socket connection to enable interprocess communication. Therefore CamClient does not know what it is looking at, it just passes the attributes/function calls to the actual interface, e.g. https://github.com/stefsmeets/instamatic/blob/2be8cdb1e2337b1df437868a8de50878d178bd88/instamatic/camera/camera_simu.py#L11 The .get_attrs method then copies the function signatures across so that tab completion and doc strings are available in IPython.

kttn8769 commented 4 years ago

Ok, I understand the point.

Thank you for your kind explanation!