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:
#
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