0

I would like to close all the previously created tasks in the nidaqmx-python module.

How can I do this?

In example, I have a number of previously opened tasks:

for i in range(10):
    nidaqmx.Task()

which I did not close. However, I want to close them now.

blaz
  • 4,108
  • 7
  • 29
  • 54
  • You probably want to save the return values of `.Task()` and then later call a method on that returned object. –  Mar 07 '18 at 15:05

2 Answers2

2

According to the source, you'll have to do something like the following:

tasks = []
for i in range(10):
    tasks.append(nidaqmx.Task())

# Some code ...

for task in tasks:
    task.close() 

See https://github.com/ni/nidaqmx-python/blob/master/nidaqmx/task.py#L448

  • I do not have the tasks saved in a list. Lets say the program crashed between measurements. – blaz Mar 07 '18 at 15:13
  • Are the task names fixed? IE could you attempt to clear the task on EXE start and handle the error? – shmicah Mar 07 '18 at 18:00
1

Have you tried using a reset_device() on the device you are using? It should make all tasks associated with the device able to be started again.

edit: though it cleared the tasks, but it only aborts them.

berna1111
  • 1,811
  • 1
  • 18
  • 23
  • Just a remark: this is a last resort! You should keep a list of open tasks and close them, or use the structure `with nidaqmx.Task() as task:` to let the code handle open and close tasks. – berna1111 Mar 09 '18 at 21:14