# How many tags can tag.readBlocking handling?

**URL:** <https://forum.inductiveautomation.com/t/how-many-tags-can-tag-readblocking-handling/58005>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [April 4, 2022, 3:31pm UTC](https://forum.inductiveautomation.com/t/how-many-tags-can-tag-readblocking-handling/58005 "2022-04-04T15:31:42Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 4, 2022, 7:45pm UTC](https://forum.inductiveautomation.com/t/how-many-tags-can-tag-readblocking-handling/58005/3 "2022-04-04T19:45:37Z")

</div>

First, this appears to be in a tag change event. You should avoid long running scripts in tag change events. I would recommend that you refactor this to be used with a Gateway Tag Change Event.

This is due to the way that Tag Change Events work. You can read more on that here:

> [@Scripting architecture choices](https://forum.inductiveautomation.com/t/scripting-architecture-choices/56976):
>
> I am looking at cleaning up my first Ignition project that was released to the wild (Under v8.1). While it works I didn’t make the best design choices which has resulted in a complicated (IE ugly) maintenance process. The application itself is basically a data logging system that monitors multiple machines (each defined by an instance of a single UDT) and writes values to a DB on both value changed and timed events. It also has no display screens of any sort. The current architecture has 3 v…

Second, you should be using `system.runPrepUpdate()`

```python
from itertools import chain
if not initialChange:
    logstart = system.date.now()
    logger = system.util.getLogger("Heartbeat event trigger")
    oktoreadpath = '[default]_tmp/_HeartBeat_event_monitoring/ReadAreaOk2Read'
    ReadLengthpath = '[default]_tmp/_HeartBeat_event_monitoring/ReadLength'
    dbresultpath = '[default]_tmp/_HeartBeat_event_monitoring/DBResult'
    paths = [oktoreadpath,ReadLengthpath]
    [oktosend , readlength] = system.tag.readBlocking(paths)
    readlength = readlength.value
    if oktosend.value == 1 and readlength >0:
        parentPath = '[default]_tmp/_HeartBeat_event_monitoring/_HeartBeat_event_read/_DPP_Read_HBEvent_{}_/'
        eventpaths = [pPath + name for pPath in [parentPath.format(e) for e in range(readlength)] for name in ['Integer00','Integer01','Integer02','Integer03','TimeInBuffer']]
        taglist = system.tag.readBlocking(eventpaths)
        querystring = "INSERT INTO heartbeat_event (equipid,heartbeatc,heartbeatp,tsc,createdate,logid) values "
        querystring += ','.join(['(?,?,?,?,?,?)'] * (readlength / 5))
        querystring += ';'
        def step(xs):
            start = 0
            step = 5
            for x in xs:
                if start > (len(xs)-step):
                    break
                yield (start, xs[start])
                start += step

        eventlist = list(chain.from_iterable([[taglist[y].value,taglist[y+1].value,taglist[y+2].value,system.date.addMillis(currentValue.timestamp,taglist[y+4].value*(-1),currentValue.timestamp, taglist[y+3].value] for y,tag in step(taglist)]))
    system.db.runPrepUpdate(querystring,eventlist,_dataBase)
    logstop = system.date.now()
    logger.info("heart beat trigger end successed take {}ms".format(system.date.millisBetween(logstart,logstop))
```

---

_[View the full topic](https://forum.inductiveautomation.com/t/how-many-tags-can-tag-readblocking-handling/58005)._
