@@ -1394,6 +1394,24 @@ Wait for events on the epoll file descriptor for a maximum time of timeout\n\
13941394in seconds (as float). -1 makes poll wait indefinitely.\n\
13951395Up to maxevents are returned to the caller." );
13961396
1397+ static PyObject *
1398+ pyepoll_enter (pyEpoll_Object * self , PyObject * args )
1399+ {
1400+ if (self -> epfd < 0 )
1401+ return pyepoll_err_closed ();
1402+
1403+ Py_INCREF (self );
1404+ return (PyObject * )self ;
1405+ }
1406+
1407+ static PyObject *
1408+ pyepoll_exit (PyObject * self , PyObject * args )
1409+ {
1410+ _Py_IDENTIFIER (close );
1411+
1412+ return _PyObject_CallMethodId (self , & PyId_close , NULL );
1413+ }
1414+
13971415static PyMethodDef pyepoll_methods [] = {
13981416 {"fromfd" , (PyCFunction )pyepoll_fromfd ,
13991417 METH_VARARGS | METH_CLASS , pyepoll_fromfd_doc },
@@ -1409,6 +1427,10 @@ static PyMethodDef pyepoll_methods[] = {
14091427 METH_VARARGS | METH_KEYWORDS , pyepoll_unregister_doc },
14101428 {"poll" , (PyCFunction )pyepoll_poll ,
14111429 METH_VARARGS | METH_KEYWORDS , pyepoll_poll_doc },
1430+ {"__enter__" , (PyCFunction )pyepoll_enter , METH_NOARGS ,
1431+ NULL },
1432+ {"__exit__" , (PyCFunction )pyepoll_exit , METH_VARARGS ,
1433+ NULL },
14121434 {NULL , NULL },
14131435};
14141436
0 commit comments