Transfer data between two separately running python programs.
Gillou
nospam at bigfoot.com
Fri Jan 25 14:47:19 EST 2002
Unfortunately it seems that Windows python does not support FIFO pipes
(os.mkfifo) but...
With this typically OO approach, you can plug into the SerialCollector any
analyzer object with a "feed" method.
You don't need a file as intermediate data storage.
This approach can be inproved using Queue objects (Queue module in the
standard doc) especially if the data are collected in threads.
=== file collector.py ===
class SerialCollector:
def __init__(self, dataconsumer):
self.dataconsumer = dataconsumer
# Other stuffs
return
def havedata(self, somebytes):
self.dataconsumer.feed(somebytes)
return
def run(self):
# Start collecting
=== end collector.py ===
=== file analyzer.py ===
class DataAnalyzer:
def __init__(self):
# whatever U want
return
def feed(self, somebytes):
# Do what you want with collected data
from collector import SerialCollector
myda = DataAnalyzer()
coll = SerialCollector(myda)
coll.run()
=== end analyzer.py ===
"MDK" <mdk at mdk.com> a écrit dans le message news:
a2s48e$13t160$1 at ID-98166.news.dfncis.de...
> Using PythonWin32 extensions I have a python program (collector.py) that
> just monitors the serial port and collects data by running in a continuous
> loop.
>
> I want to get at that data from a different python program.
>
> I've considered having collector.py write the data to a file every few
> seconds and then read the file from the other program but that just
doesn't
> seem 'clean' enough.
>
> I can't import collector and then run the loop because it stops the
calling
> program execution.
>
> Any ideas on how to resolve this?
>
> Thanks
>
>
More information about the Python-list
mailing list