I have two independent processes in python: producer and consumer. Producer generates files and consumer does some processing on files.
To test both applications, I find myself constantly starting two programs, and producer has a delay function, etc. which is a pain.
What is the quickest way to implement some kind of signaling machinery in python so that consumer says "GO!" and producer starts doing things it does.
This way I can have producer running all the time.
One simple way to do this (you didn't mention what platform(s) you care about, so I'll assume you want something cross-platform) is a UDP socket with a known port. If the consumer just listens on localhost port 12345, it can block on a
sock.recvfrom
call every time it needs to wait, and the producer can do asock.sendto
to notify it.For example, here's a consumer:
And a producer:
Other things to consider: