# Threading

**URL:** <https://forum.inductiveautomation.com/t/threading/1635>\
**Category:** Ignition\
**Created:** [March 12, 2010, 7:30pm UTC](https://forum.inductiveautomation.com/t/threading/1635 "2010-03-12T19:30:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [March 12, 2010, 7:30pm UTC](https://forum.inductiveautomation.com/t/threading/1635/1 "2010-03-12T19:30:38Z")

</div>

I’ve got something I need to do that I got working correctly in Python using the threading module, but that isn’t available in Ignition. Would using the invokeAsychronous functions be the correct way to duplicate the same thing?

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [March 13, 2010, 12:08am UTC](https://forum.inductiveautomation.com/t/threading/1635/2 "2010-03-13T00:08:30Z")

</div>

I must confess that I’m not all that familiar with the python threading module.

system.util.invokeAsynchronous will call your function in a new, dedicated thread. The thread will die after your function completes. So if thats what you’re trying to duplicate, then yes.

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [March 13, 2010, 1:47am UTC](https://forum.inductiveautomation.com/t/threading/1635/3 "2010-03-13T01:47:39Z")

</div>

Yep, that’s what I’m trying to do. I didn’t know much about the threading module either until recently, but it’s actually pretty cool and makes mult-threading a cinch. But if invokeAsynchronous also creates a new thread, that’s the ticket. Thanks.

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [March 13, 2010, 4:11pm UTC](https://forum.inductiveautomation.com/t/threading/1635/4 "2010-03-13T16:11:09Z")

</div>

Ok, I’m using this to replace the ping api that I used to use in fsql. I’ve got it working about five different ways outside of Ignition, but none of them work inside of Ignition.

A stripped down version is below. It breaks on “popen”, although it seems to have been part of the os module for a long time. Is there a subsitute I could use?

```auto
for i in range(1,4):
	def pingMe(ip=i):
		import os
		ping = 'ping 127.0.0.'+str(ip)
		a = os.popen(ping)
		print a.read()

	system.util.invokeAsynchronous(pingMe)
```

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [March 15, 2010, 6:48pm UTC](https://forum.inductiveautomation.com/t/threading/1635/5 "2010-03-15T18:48:49Z")

</div>

There was no os.popen in Python 2.1, see [docs.python.org/release/2.1/lib/os-process.html](http://docs.python.org/release/2.1/lib/os-process.html)

I would use Java for this (frequent readers are suprised, I’m sure).

For example, your code could work like this:

[code]for i in range(1,4):  
def pingMe(ip=i, timeout=15000):  
from [java.net](http://java.net) import InetAddress  
addr = InetAddress.getByName(‘127.0.0.%d’ % ip)  
print addr.isReachable(timeout)

system.util.invokeAsynchronous(pingMe)[/code]

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [March 15, 2010, 11:34pm UTC](https://forum.inductiveautomation.com/t/threading/1635/6 "2010-03-15T23:34:21Z")

</div>

> [@Carl.Gould](#):
>
> There was no os.popen in Python 2.1, see [docs.python.org/release/2.1/lib/os-process.html](http://docs.python.org/release/2.1/lib/os-process.html)

Hmm, when I was digging around before, I found a ref to popen here: [http://docs.python.org/release/2.1/lib/os-newstreams.html](http://docs.python.org/release/2.1/lib/os-newstreams.html)

I figured I could use it to run something from the command line, but I guess it doesn't work that way.

[quote]  
I would use Java for this (frequent readers are suprised, I'm sure).

For example, your code could work like this:

[code]for i in range(1,4):  
def pingMe(ip=i, timeout=15000):  
from [java.net](http://java.net) import InetAddress  
addr = InetAddress.getByName('127.0.0.%d' % ip)  
print addr.isReachable(timeout)

system.util.invokeAsynchronous(pingMe)[/code][/quote]

Hey, I'm easy. Java is perfectly fine by me. I'll try it in my project tomorrow. Thanks!
