- jclass writerClass = (*env)->FindClass(env, WRITER_CLASS);
- jmethodID writeMethod = (*env)->GetMethodID(env, writerClass, "write", "([CII)V");
- jcharArray chars = (*env)->NewCharArray(env, (jsize)length);
-
- (*env)->SetCharArrayRegion(env, chars, 0, length, what);
- (*env)->CallVoidMethod(env, sclWriter, writeMethod, chars, 0, length);
+ PyThreadState *my_ts = PyThreadState_Get();
+ if (my_ts == main_ts) {
+ jclass writerClass = (*env)->FindClass(env, WRITER_CLASS);
+ jmethodID writeMethod = (*env)->GetMethodID(env, writerClass, "write", "([CII)V");
+ jcharArray chars = (*env)->NewCharArray(env, (jsize)length);
+
+ (*env)->SetCharArrayRegion(env, chars, 0, length, what);
+ Py_BEGIN_ALLOW_THREADS
+ (*env)->CallVoidMethod(env, sclWriter, writeMethod, chars, 0, length);
+ Py_END_ALLOW_THREADS
+ } else {
+ //TODO
+ }