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?
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.
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.
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?
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)
There was no os.popen in Python 2.1, see 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 import InetAddress
addr = InetAddress.getByName(‘127.0.0.%d’ % ip)
print addr.isReachable(timeout)
system.util.invokeAsynchronous(pingMe)[/code]
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
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 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!