Sequencer "Target" steps - what do they do?

Anything that doesn't fit into any of the other forums
lowenthalm
Posts: 224
Joined: Mon May 07, 2018 12:27 am

Re: Sequencer "Target" steps - what do they do?

#11

Post by lowenthalm »

That link helped a lot. I realized that was probably what was going on once I tried to prowl around in the help() system and ran into so many problems.

The thing that concerns me at this point is all the Task objects in the SharpCap Python API are in fact .NET Task objects (in System.Threading.Tasks), not Python Task objects (in asyncio.tasks).

You can not tell the difference between the two Task classes in the Iron Python console when the pop up help menu shows you the function calls in the various SharpCap objects. Most people will be looking at the online Python docs, as that is where almost everything you need can be found, and people will go there first when looking up how SharpCap Task objects work. The only way to know the Task object is different is to actually get an instance from the SharpCap API and then inspect it, which is what I did. Even then, the help( some_Task_object_instance ) I performed gives bogus results, so I still couldn't tell I didn't have a Python Task class object.

I might suggest adding a caveat in the helpme() function in the SharpCap Iron Python console that warns about SharpCap Tasks being derived from .Net, rather than the standard Python libraries (and pointing to the .NET API link you sent me). Also, the online scripting docs make no mention of this, so I think it might be helpful to warn about the Task object there too.

There are some other .NET derived classes in the SharpCap API, I think, but this has so far not really been important for me to know about. The Task case is particularly problematic because it's a name collision between the two threading implementations.

I also noticed that the on-line scripting docs confusingly dissuade users from using Async methods:
Where possible, use the non-async version of the method – for instance RunCapture rather than RunCaptureAsync. If you need to use an Async method from Python scripting, you can use .Wait() or .Result to wait for completion or access the result (return value) of the asynchronous method.
Its seems that using these async methods has recently been the cure to a lot of interfaces freezes I have been trying to eliminate in my Python code.
User avatar
admin
Site Admin
Posts: 17588
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Sequencer "Target" steps - what do they do?

#12

Post by admin »

Hi,

in essence, all of the scripting API is .NET, it's just that the IronPython runtime maps some of the .NET types onto python types automatically (like strings, for instance, and some collections), whereas others are dealt with purely in their .NET form (tasks, etc).

A lot of what is recommended or not depends on the way that you call the API - in the normal 'run from the console' API way, the non-async types are preferred as they run in a worker thread and it doesn't matter if they block - it doesn't affect anything else. On the other hand, if you are doing stuff in response to a custom button (or a form shown from scripting), you are running script code in the UI thread and you have to be much more careful.

Handling async .NET calls with .NET tasks from Python is hard to get right, hence my original advice of avoiding it if possible. I am still wondering if the right approach would be to jump execution to a background thread after handling the custom button, rather than to continue in the UI thread, but that introduces new problems if you make your own custom UI :(

cheers,

Robin
Post Reply