Преглед изворни кода

starpupy: fix bugs about use of -m asyncio in Python interpreter

HE Kun пре 4 година
родитељ
комит
c4139547da
2 измењених фајлова са 19 додато и 1 уклоњено
  1. 13 1
      starpupy/src/joblib.py
  2. 6 0
      starpupy/src/starpu_task_wrapper.c

+ 13 - 1
starpupy/src/joblib.py

@@ -32,6 +32,15 @@ except:
 import inspect
 import threading
 
+loop = asyncio.get_event_loop()
+if (loop.is_running()):	
+	try:
+		import nest_asyncio
+		nest_asyncio.apply()
+		has_nest=True
+	except ModuleNotFoundError as e:
+		has_nest=False
+
 BACKENDS={
 	#'loky': LokyBackend,
 }
@@ -245,7 +254,10 @@ class Parallel(object):
 				return res
 			#asyncio.run(asy_main())
 			#retVal=asy_main
-			loop = asyncio.get_event_loop()
+			#loop = asyncio.get_event_loop()
+			if(loop.is_running() and not has_nest):
+				raise starpupy.error("Can't find \'nest_asyncio\' module (consider running \"pip3 install nest_asyncio\" or try to remove \"-m asyncio\" when starting Python interpreter)")
+			
 			results = loop.run_until_complete(asy_main())
 			retVal = results
 		# the mode future, user needs to use asyncio module and await the Future result in main function

+ 6 - 0
starpupy/src/starpu_task_wrapper.c

@@ -440,6 +440,12 @@ static PyObject* starpu_task_submit_wrapper(PyObject *self, PyObject *args)
 	/*create a asyncio.Future object*/
 	PyObject *fut = PyObject_CallMethod(loop, "create_future", NULL);
 
+	if (fut == NULL)
+	{
+		PyErr_Format(StarpupyError, "Can't find asyncio module (try to add \"-m asyncio\" when starting Python interpreter)");
+		return NULL;
+	}
+
 	/*first argument in args is always the python function passed in*/
 	PyObject *func_py = PyTuple_GetItem(args, 0);