[Tutor] running multiple concurrent processes

richard kappler richkappler at gmail.com
Sat Nov 3 21:20:54 CET 2012


To all, especially Dave, Oscar and Ramit, thanks for the discussion and
help. Tino, as soon as I have something to put up, I will gladly put it up
on Github. At the moment I only have a few snippets I've written in trying
to learn the various bits everyone has been helping me with.

Just for the record, I did use subprocess quite successfully in one of my
preliminary programs earlier this summer as I started to learn python, used
it to send out the text from the old chatbot to Festival TTS, so I am
comfortable with the idea of running multiple processes from python to the
command line. I'm not quite sure that's the way to go with the sensors and
other bits though.

I'm wondering if I'm asking the wrong question. I have read and re-read
your posts, and have read and re-read the documentation on multi-processing
and threading. I have also read several tutorials on both. I feel that I
understand the concepts a wee bit better, though not enough to come up with
some workable processing or threading code. I have, however, still not
figured out an answer to my question, which leads me to believe I have not
asked the question properly. The alternative is that I'm just too damned
dense to wrap my arms around this and I both think and hope that is not the
case, so I will try to do a better job of articulating what I'm looking
for. (Again, I suspect its in multiprocessing and threading, but I can't
quite put my finger on a good approach).

SO... while the bot program is running, I would like it to be continuously
cognizant of the sensor data and any changes in that data. Let's distill it
down to a single sensor to simplify the discussion. If I have a temperature
sensor feeding data to the arduino, which feeds that data through serial to
the Python program (let's call that pyBrain) that "is" the bot, (here's the
meat of the question:) how do I make the pyBrain constantly aware of the
temperature while doing other stuff?

I think what's tripping me up is that Python is sequential, yes? So line 1
executes, then we go to line 2, then line 3, etc. So if pyBrain is off
doing some facial recognition or having a chat (or both?), and Temp1
suddenly rises above a preset threshold of 78 degrees F how does pyBrain
know that? Because python is sequential does there not have to be some
specific code that tells it to periodically poll Temp1? Or, barring
periodic or even continuous polling, is there some "event alert" function
that would tell the pyBrain program to execute the "Temp1High" function?

And if there is an event alert function such that you all are going to tell
me (in your best Frank Morgan voice) "Well, wny didn't you say so?" then
can pyBrain keep chatting etc and just update "state", aware that it's
environment has changed, keeping that information for future reference, but
continue on with it's running tasks/processes unless that new state
requires some action? Or even better, add the action to the task(s) it is
performing as one more concurrent task/action?

My initial thought was to run concurrent processes, or threads (still
working that bit out). I have considered having Arduino write the sensor
data to a table or dictionary or even file, just constantly overwriting
previous values, and pyBrain could pull values out of that
table/dictionary/file as needed. That doesn't seem terribly elegant to me
though, and certainly doesn't get me passed the "parameter just crossed a
preset threshold" alert issue either.

Befuddled and bewildered while learning at an alarming rate, Richard

-- 

quando omni flunkus moritati
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121103/571d9498/attachment.html>


More information about the Tutor mailing list