[Cs-dev] Python message callback and threads
Date | 2010-06-11 13:01 |
From | Victor Lazzarini |
Subject | [Cs-dev] Python message callback and threads |
Ok, I have a fair idea of what is going on now with the message callback in Python. Basically it's a problem with GIL, as I expected. What happens is that when the performance thread finishes and Join() is called, the thread-safety function calls I placed in the message callback wrapper start misbehaving and hang. One work-around I tried is to set the message callback to None, for which I have made now a special provision to call a void function, so the callback does not call the offending Python API function. It's a bit of a hack, but works for the moment until I can think of a better solution. Anyway, I'm hoping to be able to provide a better solution to this problem later. Victor ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2010-06-11 13:32 |
From | Victor Lazzarini |
Subject | Re: [Cs-dev] Python message callback and threads |
A quick example of what I mean: import sys, csnd, time if len(sys.argv) < 2: print "Give a csd file in argument" sys.exit() else: csdfile = sys.argv[1] loglines = [] def logger(str): print str loglines.append(str) cs = csnd.Csound() cs.SetMessageCallback(logger) res = cs.Compile(csdfile) if res == 0: perf = csnd.CsoundPerformanceThread(cs) perf.Play() while perf.GetStatus() == 0: pass perf.Stop() cs.SetMessageCallback(None) time.sleep(1) print "stopped" perf.Join() The fix is in CVS now. Victor On 11 Jun 2010, at 13:01, Victor Lazzarini wrote: > Ok, I have a fair idea of what is going on now with the message > callback in Python. Basically it's a problem with GIL, as I expected. > What happens is that when the performance thread finishes and Join() > is called, the thread-safety function calls I placed in the message > callback wrapper start misbehaving and hang. > One work-around I tried is to set the message callback to None, for > which I have made now a special provision to call a void function, so > the callback does not call the offending Python API function. It's a > bit of a hack, but works for the moment until I can think of a better > solution. > > Anyway, I'm hoping to be able to provide a better solution to this > problem later. > > Victor > > ------------------------------------------------------------------------------ > ThinkGeek and WIRED's GeekDad team up for the Ultimate > GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the > lucky parental unit. See the prize list and enter to win: > http://p.sf.net/sfu/thinkgeek-promo > _______________________________________________ > Csound-devel mailing list > Csound-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/csound-devel ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2010-06-11 13:36 |
From | Olivier Bélanger |
Subject | Re: [Cs-dev] Python message callback and threads |
Attachments | None None |
Thanks Victor, I'll take a look at it. Is the 1 second sleep necessary? It's a little bit long... Olivier 2010/6/11 Victor Lazzarini <Victor.Lazzarini@nuim.ie> A quick example of what I mean: |
Date | 2010-06-11 14:11 |
From | Victor Lazzarini |
Subject | Re: [Cs-dev] Python message callback and threads |
Attachments | None None |
For some reason, I need sometimes to wait a bit before Join(), as the SetMessageCallback() sometimes is too late setting the callback to None. But if you have another means of delaying the call to Join() Victor On 11 Jun 2010, at 13:36, Olivier Bélanger wrote: Thanks Victor, |