Uncategorized

python multiprocessing program

Asked 
Viewed 19 times
-1

I am so frustrated with this problem, please help me if anyone knows whats happening here..

I am using pigpio in python 2.7/raspberry pi. the purpose is to control three devices over serial. It works well when I do step by step but somehow multiprocesing messes up something. I’ve tried to use multiprocessing with Lock, but it seems doesn’t help at all.

def pjt_bright(pjt_n,brightness): # PJT[x], brightness : 0-1000
    fade_nr=bytearray.fromhex('{:02x}'.format(249)+'{:02x}'.format(16+(brightness//128)*2)+'{:02x}'.format((brightness%128)*2))
    #print "fade number      =    ",brightness,"       projector nr    =      ", pjt_n
    pi.wave_clear()
    pi.wave_add_serial(pjt_n, BAUD, fade_nr)
    time.sleep(0.1)
    faderun=pi.wave_create()
    pi.wave_send_once(faderun)

def pjt_fade1(pjt_n,flag,gap,lock): #MAX 50 MIN -2sec min 3
        with lock:
            pjt_bright(pjt_n,0)
        for i in range(1000//gap):
            with lock:
                b=i*gap
                pjt_bright(pjt_n, b) #int|(i*gap)
                time.sleep(0.15)
        time.sleep(2) #top notch and will go fade down
        for i in range(1000//gap,-1,-1):
            with lock:
                b=i*gap
                pjt_bright(pjt_n, b) #int|(i*gap)
                time.sleep(0.15)

And the actual call happens

fading1=multiprocessing.Process(target=pjt_fade1, args=[PJT[1],1,int(round(np.interp(idx_s[1][0],[0,9],[10,41]))),lock])

the error messages, it really depends but usually

`File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 2275, in wave_create
    return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, 0, 0))
      File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 979, in _u2i
        raise error(error_text(v))
    error: 'attempt to create an empty waveform'`
 New contributor

  • 1
    code fragments are meaningless – Milliways 17 hours ago
  • It is very difficult to troubleshoot mutiprocessing programs. Your program of 2,000+ lines long makes it mission impossible for others who don’t know what is going on. Perhaps you can (1) “simplify” it to a pool of just two pseudo serial (or just plain user key pressing) processes, or (2) use semaphore instead of lock. If you give a what Stack Oveflow/Exchange recommended MCV (“Minimal”, “Complete”, “Verifiable”) style python program, I might try to see how I can write and verify a similar, as short as possible, but not shorter, python 3.7.3 mp program using pool, condition, and semaphore. – tlfong01 17 hours ago
  • 1
    How to create a Minimal, Reproducible Example: stackoverflow.com/help/minimal-reproducible-example – tlfong01 16 hours ago

 

.END

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: