module cwiid and threading: how to use cwiid.Wiimote without blocking

N

News123

Hi,

I'm using the module cwiid to conncet to a wiimote.

import cwiid
wiimote = cwiid.Wiimote()

This function is blocking:
It waits until it could sucessfully connect to a device or
until 20 seconds passed without sucessful connection.

As I wanted to do some things even if the wii-mote is not
connected I though about creating a thread, which tries connecting
until it is sucessfully connected
and let the application do something else meanwhile.

Unfortunately it seems, that the call to cwiid.Wiimote() blocks
all threads.
Probably the call to Wiimote() doesn't release the GIL.


So my question:

Is there anybody knowing if there's any trick in python or
in libcwiid to avoid this 'complete block'

The only idea, that I have is to do the polling in a second process.
I'm just not sure though how I could pass the sucessfully connected
device to the parent process without creating pipes or

thanks for any ideas and bye

N

P.S. Attached a test script and its output:

#
Code:
import os,sys,time,threading,cwiid
class wii_thread(threading.Thread):
    def run(self):
        wm = None
        while not wm:
            try:
                print "try to connect"
                wm=cwiid.Wiimote()
            except:
                print "Didn't find wiimote will retry"
                time.sleep(0.5)
        print "setup wiimote,poll and queue wii events"
        time.sleep(1000)
if __name__ == '__main__':
    wii_thrd = wii_thread()
    wii_thrd.start()
    while True:
        print 'do something'
        time.sleep(1)
#[code end]

# the output
##################
do something
try to connect
No wiimotes found
Didn't find wiimote will retry
do something
try to connect
setup wiimote,poll and queue wii events
do something
do something
do something
Traceback (most recent call last):
  File "./threadprob.py", line 22, in <module>
    time.sleep(1)
KeyboardInterrupt
 
N

News123

The only solution, that I found was recompiling the libcwiid wrapper,
such that it allows threading (the patch existed already on the libcwiid
Trac data base, though it's not part of an official release)


bye


N
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top