First page Back Continue Last page Overview Graphics
Threading and SWIG
// deal with data being returned
int usb_bulk_read_wrapped(usb_dev_handle *dev, int ep, char *bytesoutbuffer, int *bytesoutbuffersize, int timeout)
{
int res;
Py_BEGIN_ALLOW_THREADS
res=usb_bulk_read(dev, ep, bytesoutbuffer, *bytesoutbuffersize, timeout);
Py_END_ALLOW_THREADS
if (res<=0)
*bytesoutbuffersize=0;
else
*bytesoutbuffersize=res;
return res;
}
Notes:
This demonstrates how easy it is to allow threading (the bold lines). It also demonstrates the use of parameter names to give cues to SWIG (bytesoutbuffer and bytesoutbuffersize are combined by SWIG to represent a binary string in Python – ie two seperate parameters at the C level become one at the Python level)