Issue #54 resolved

pygame.examples.movieplayer causes "PyThreadState_Get: no current thread"

created an issue

== Lenard Lindstrom, 2010-09-22 13:12:23 -0700

{{{ Python 3.2, r84925

Running the example on an mpg file raises the following Python exception:

Fatal Python error: PyThreadState_Get: no current thread

This is the the gdb stack listing just before the exception is raised: pystate is NULL.

Breakpoint 1, PyThreadState_Get () at Python/pystate.c:372 372 if (tstate == NULL) (gdb) where

0 PyThreadState_Get () at Python/pystate.c:372

1 0x080ace8f in PyEval_AcquireLock () at Python/ceval.c:327

2 0xb77ec946 in rw_read_th (context=0x8e06e78, ptr=0x8e09020, size=1,

maxnum=16384) at src/rwobject.c:526

3 0xb733cb55 in MPEGsystem::Read() () from /usr/lib/

4 0xb733cf2f in MPEGsystem::seek_first_header() ()

from /usr/lib/

5 0xb733d3eb in MPEGsystem::MPEGsystem(SDL_RWops*) ()

from /usr/lib/

6 0xb733a970 in MPEG::Init(SDL_RWops*, bool) ()

from /usr/lib/

7 0xb733ab1b in MPEG::MPEG(SDL_RWops*, bool) ()

from /usr/lib/

8 0xb73406e2 in SMPEG_new_rwops () from /usr/lib/

9 0xb74391ca in Movie (self=0xb754d99c, arg=0x8d04114) at src/movie.c:489

10 0x08198dee in PyCFunction_Call (func=0xb754d9d4, arg=0x8d04114, kw=0x0)

at Objects/methodobject.c:81

11 0x080be8d9 in call_function (pp_stack=0xbfffc154, oparg=1)

at Python/ceval.c:3870

12 0x080b9b5d in PyEval_EvalFrameEx (f=0x8d7a264, throwflag=0)

at Python/ceval.c:2669

13 0x080bed26 in fast_function (func=0x8cd881c, pp_stack=0xbfffc924, n=1,

na=1, nk=0) at Python/ceval.c:3958

---Type <return> to continue, or q <return> to quit---

14 0x080bea68 in call_function (pp_stack=0xbfffc924, oparg=1)

at Python/ceval.c:3891

15 0x080b9b5d in PyEval_EvalFrameEx (f=0x8d79f5c, throwflag=0)

at Python/ceval.c:2669

16 0x080bcdc7 in PyEval_EvalCodeEx (co=0xb7b1ab20, globals=0xb7c66f34,

locals=0xb7c66f34, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, 
defcount=0, kwdefs=0x0, closure=0x0) at Python/ceval.c:3306

17 0x080ad8c5 in PyEval_EvalCode (co=0xb7b1ab20, globals=0xb7c66f34,

locals=0xb7c66f34) at Python/ceval.c:761

18 0x080a7829 in builtin_exec (self=0xb7e22964, args=0x8d046fc)

at Python/bltinmodule.c:778

19 0x08198dee in PyCFunction_Call (func=0xb7e26034, arg=0x8d046fc, kw=0x0)

at Objects/methodobject.c:81

20 0x080be8d9 in call_function (pp_stack=0xbfffd234, oparg=2)

at Python/ceval.c:3870

21 0x080b9b5d in PyEval_EvalFrameEx (f=0x8d79c14, throwflag=0)

at Python/ceval.c:2669

22 0x080bcdc7 in PyEval_EvalCodeEx (co=0xb7b1ad90, globals=0xb7adf0d4,

locals=0x0, args=0x833e748, argcount=7, kws=0x833e764, kwcount=0, 
defs=0xb7b3b8b8, defcount=5, kwdefs=0x0, closure=0x0)
at Python/ceval.c:3306

23 0x080bee26 in fast_function (func=0xb7b3cd44, pp_stack=0xbfffdaf4, n=7,

na=7, nk=0) at Python/ceval.c:3968

24 0x080bea68 in call_function (pp_stack=0xbfffdaf4, oparg=7)

at Python/ceval.c:3891

25 0x080b9b5d in PyEval_EvalFrameEx (f=0x833e5dc, throwflag=0)

at Python/ceval.c:2669

26 0x080bcdc7 in PyEval_EvalCodeEx (co=0xb7ae1090, globals=0xb7adf0d4,

locals=0x0, args=0xb7b36be0, argcount=2, kws=0x0, kwcount=0, 
defs=0xb7b3ac50, defcount=1, kwdefs=0x0, closure=0x0)
at Python/ceval.c:3306

27 0x0817ec94 in function_call (func=0xb7ad0d44, arg=0xb7b36bcc, kw=0x0)

at Objects/funcobject.c:630

28 0x0814f4bc in PyObject_Call (func=0xb7ad0d44, arg=0xb7b36bcc, kw=0x0)

at Objects/abstract.c:2149

29 0x080fd934 in RunModule (

modname=0xb7dfe028 L"pygame.examples.movieplayer", set_argv0=1)
at Modules/main.c:216

30 0x080fe7e4 in Py_Main (argc=4, argv=0xb7dfc028) at Modules/main.c:641

31 0x0805c2f1 in main (argc=4, argv=0xbffff464) at ./Modules/python.c:50

(gdb) cont Continuing. Fatal Python error: PyThreadState_Get: no current thread

Program received signal SIGABRT, Aborted. 0xb7fe2424 in __kernel_vsyscall ()

This message does not appear for earlier Python versions. So it could be a Python 3.2 bug. It is an alpha release. Or it could be that 3.2 has better thread checking, and that this problem has been around in Pygame from the beginning.

The rwobject module's threaded file rwops makes calls to PyEval_AcquireLock and PyEval_ReleaseLock, but does nothing in initialize the thread. An improperly initialed thread may explain the sporadic problems with the movie and mixer modules reported over the years. So the first question is, how is a thread added Python? The documentation on this is basically non-existent. The second is, where to do the initialization and finalization? The SDL rwops structure has a close function, but no open. One possibility is to start the thread from the Pygame extension module, then call smpeg or SDL_mixer or whatever without threading. }}}

== Lenard Lindstrom, 2010-09-22 20:21:06 -0700

{{{ The solution may be PyGILState_Ensure and PyGILState_Release, described in PEP 311 ( ). A preliminary test with rwobject.c and the movie module looks promising. }}}

== Lenard Lindstrom, 2011-05-19 10:05:09 -0700

{{{ Fixed in rev 2937. Should be tested on Windows before closing. }}}

== Lenard Lindstrom, 2011-05-19 12:53:33 -0700

{{{ Tested on Windows XP with Python 3.2

Bug Closed. }}}

Comments (0)

  1. Log in to comment