How to handle exception in using(Py.GIL()) block pythonnet

633
March 13, 2017, at 7:23 PM

Is there a way to handle exception in using(Py.GIL()) block?

For example:

   using System;
   using Python.Runtime;
   public class Test{
        public static void Main(){
           using(Py.GIL()){
               try{
                   dynamic module = Py.Import("module");
                   dynamic result = module.function("argument");
                   Console.WriteLine(result);
               }
               catch(Excepiton ex){
                   // Handled Exception
               }
           }
        }
    }

I asked this question because, I call C# function which use using(Py.GIL()) block. It is executed with a new thread which the Main thread waits for it to finish. It works for the first round, and for the next, it stop on the using block and the application freezes with out showing any exception.

I even tried to stop the Main thread from waiting the execution, but all the worker thread execution still stops at the using block of Py.GIL() after the first round.

For the thread execution I am using Thread pool.

Thread.Factory.StartNew(FunctionName);
Rent Charter Buses Company
READ ALSO
CNTK deactivate gpu locking with python API

CNTK deactivate gpu locking with python API

How can I deactivate the GPU locking by cntk from the python API (20 beta 12

601
can't serialize <type 'array.array'>

can't serialize <type 'array.array'>

I am trying to load a file(pkl) pickled in jython and access it through python using execnet

295
Recording Time taken to type sentence(Code not working)

Recording Time taken to type sentence(Code not working)

I've recently started coding and I thought about making this little programIt displays a sentence and the user has to type it as quickly as possible, then it returns the time taken for them to type it

348
Detect Duplicates in certain columns in a DataFrame &amp; Perform operations on these

Detect Duplicates in certain columns in a DataFrame & Perform operations on these

Following on from this question, here is the input / output I wantI have some ideas though not entirely sure

370