@@ -2521,27 +2521,32 @@ static PyObject *
25212521channel_send (PyObject * self , PyObject * args , PyObject * kwds )
25222522{
25232523 // XXX Add a timeout arg.
2524- static char * kwlist [] = {"cid" , "obj" , "wait" , NULL };
2525- int64_t cid ;
2524+ static char * kwlist [] = {"cid" , "obj" , "blocking" , "timeout" , NULL };
25262525 struct channel_id_converter_data cid_data = {
25272526 .module = self ,
25282527 };
25292528 PyObject * obj ;
2530- int wait = 1 ;
2531- if (!PyArg_ParseTupleAndKeywords (args , kwds , "O&O|$p:channel_send" , kwlist ,
2529+ int blocking = 1 ;
2530+ PyObject * timeout_obj = NULL ;
2531+ if (!PyArg_ParseTupleAndKeywords (args , kwds , "O&O|$pL:channel_send" , kwlist ,
25322532 channel_id_converter , & cid_data , & obj ,
2533- & wait )) {
2533+ & blocking , & timeout_obj )) {
2534+ return NULL ;
2535+ }
2536+
2537+ int64_t cid = cid_data .cid ;
2538+ PY_TIMEOUT_T timeout ;
2539+ if (PyThread_ParseTimeoutArg (timeout_obj , blocking , & timeout ) < 0 ) {
25342540 return NULL ;
25352541 }
2536- cid = cid_data .cid ;
25372542
2538- if (wait ) {
2543+ if (blocking ) {
25392544 PyThread_type_lock mutex = PyThread_allocate_lock ();
25402545 if (mutex == NULL ) {
25412546 PyErr_NoMemory ();
25422547 return NULL ;
25432548 }
2544- PyThread_acquire_lock (mutex , WAIT_LOCK );
2549+ PyThread_acquire_lock (mutex , NOWAIT_LOCK );
25452550
25462551 /* Queue up the object. */
25472552 int err = _channel_send (& _globals .channels , cid , obj , mutex );
@@ -2551,7 +2556,6 @@ channel_send(PyObject *self, PyObject *args, PyObject *kwds)
25512556 }
25522557
25532558 /* Wait until the object is received. */
2554- PY_TIMEOUT_T timeout = -1 ;
25552559 if (wait_for_lock (mutex , timeout ) < 0 ) {
25562560 return NULL ;
25572561 }
@@ -2568,35 +2572,40 @@ channel_send(PyObject *self, PyObject *args, PyObject *kwds)
25682572}
25692573
25702574PyDoc_STRVAR (channel_send_doc ,
2571- "channel_send(cid, obj, wait =True)\n\
2575+ "channel_send(cid, obj, blocking =True)\n\
25722576\n\
25732577Add the object's data to the channel's queue.\n\
25742578By default this waits for the object to be received." );
25752579
25762580static PyObject *
25772581channel_send_buffer (PyObject * self , PyObject * args , PyObject * kwds )
25782582{
2579- static char * kwlist [] = {"cid" , "obj" , "wait" , NULL };
2580- int64_t cid ;
2583+ static char * kwlist [] = {"cid" , "obj" , "blocking" , "timeout" , NULL };
25812584 struct channel_id_converter_data cid_data = {
25822585 .module = self ,
25832586 };
25842587 PyObject * obj ;
2585- int wait = 1 ;
2588+ int blocking = 1 ;
2589+ PyObject * timeout_obj = NULL ;
25862590 if (!PyArg_ParseTupleAndKeywords (args , kwds ,
2587- "O&O|$p :channel_send_buffer" , kwlist ,
2591+ "O&O|$pO :channel_send_buffer" , kwlist ,
25882592 channel_id_converter , & cid_data , & obj ,
2589- & wait )) {
2593+ & blocking , & timeout_obj )) {
2594+ return NULL ;
2595+ }
2596+
2597+ int64_t cid = cid_data .cid ;
2598+ PY_TIMEOUT_T timeout ;
2599+ if (PyThread_ParseTimeoutArg (timeout_obj , blocking , & timeout ) < 0 ) {
25902600 return NULL ;
25912601 }
2592- cid = cid_data .cid ;
25932602
25942603 PyObject * tempobj = PyMemoryView_FromObject (obj );
25952604 if (tempobj == NULL ) {
25962605 return NULL ;
25972606 }
25982607
2599- if (wait ) {
2608+ if (blocking ) {
26002609 PyThread_type_lock mutex = PyThread_allocate_lock ();
26012610 if (mutex == NULL ) {
26022611 Py_DECREF (tempobj );
@@ -2614,7 +2623,6 @@ channel_send_buffer(PyObject *self, PyObject *args, PyObject *kwds)
26142623 }
26152624
26162625 /* Wait until the buffer is received. */
2617- PY_TIMEOUT_T timeout = -1 ;
26182626 if (wait_for_lock (mutex , timeout ) < 0 ) {
26192627 return NULL ;
26202628 }
@@ -2632,7 +2640,7 @@ channel_send_buffer(PyObject *self, PyObject *args, PyObject *kwds)
26322640}
26332641
26342642PyDoc_STRVAR (channel_send_buffer_doc ,
2635- "channel_send_buffer(cid, obj, wait =True)\n\
2643+ "channel_send_buffer(cid, obj, blocking =True)\n\
26362644\n\
26372645Add the object's buffer to the channel's queue.\n\
26382646By default this waits for the object to be received." );
0 commit comments