Python interpreters in threads crash the application

Discussion in 'Python' started by grbgooglefan, Apr 15, 2009.

  1. grbgooglefan

    grbgooglefan Guest

    I have C application in which I have instantiated Python interpreter
    in each worker thread.

    When I start the program it crashes at different places in Python code
    but program never finishes normally.

    One such core dump is given below.

    Can you please help me in following queries?
    1) Can we not use Python interpreters per thread instead of having a
    common shared Python interpreter at global level/ scope?
    2) Why is this crash happening? Do I need to use locks in Python
    interpreter?
    Will that make the multiple threads work in serialized way?

    --------------------------------------------------------------------------------
    pflags core:-
    data model = _ILP32 flags = MSACCT|MSFORK
    /1: flags = STOPPED
    why = PR_SUSPENDED
    /2: flags = STOPPED
    why = PR_SUSPENDED
    /3: flags = STOPPED lwp_park(0x4,0x0,0x0)
    why = PR_SUSPENDED
    /4: flags = 0
    sigmask = 0xffffbefc,0x0000ffff cursig = SIGSEGV
    /5: flags = STOPPED lwp_park(0x4,0x0,0x0)
    why = PR_SUSPENDED
    /6: flags = STOPPED lwp_park(0x4,0x0,0x0)
    why = PR_SUSPENDED
    /7: flags = STOPPED lwp_mutex_timedlock(0xff3f0a10,0x0)
    why = PR_SUSPENDED
    /8: flags = STOPPED lwp_park(0x4,0x0,0x0)
    why = PR_SUSPENDED
    /9: flags = STOPPED lwp_park(0x4,0x0,0x0)
    why = PR_SUSPENDED
    /10: flags = STOPPED
    why = PR_SUSPENDED
    /11: flags = STOPPED lwp_park(0x4,0x0,0x0)
    why = PR_SUSPENDED
    --------------------------------------------------------------------------------
    pstack core:
    ----------------- lwp# 1 / thread# 1 --------------------
    000110e8 main (1, ffbff2d4, ffbff2dc, 21400, feec0200, feec0240)
    + 50
    00010c10 _start (0, 0, 0, 0, 0, 0) + 108
    ----------------- lwp# 2 / thread# 2 --------------------
    ff20877c string_dealloc (fed7bbfc, 53bc, ff2f6ba0, e40e0, ff2f6ba0,
    ff2dec08)
    ff213b44 PyString_InternFromString (ff316e68, 0, 0, ff316e68, e40c0,
    2000) + 20
    ff2262f8 init_slotdefs (b8964, 0, 2000, 2204, 0, 0) + 58
    ff2266b8 add_operators (ff2f76c0, 1c00, b8568, 5000, 2000, 21b0) + 1c
    ff21fe28 PyType_Ready (ff2f76c0, bef10, 0, 0, 5124, 0) + 134
    ff21fd88 PyType_Ready (ff2f7438, 1, de358, ff3b3904, 5124, 5284) + 94
    ff2008c8 _Py_ReadyTypes (0, ff308ea4, 121c20, fefc6964, 21788,
    ff06b3d4) + 1c
    ff287cc8 Py_InitializeEx (0, 0, 4000, 0, 0, ff2dec08) + 234
    00010c4c __1cMinterpthread6Fpv_0_ (0, fed7c000, 0, 0, 10c38, 0) + 14
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    ----------------- lwp# 3 / thread# 3 --------------------
    ff040154 __lwp_park (0, 0, ff06c348, 0, 0, 1) + 14
    ff02415c _flockget (ff06c348, 21878, 441b4, ff3b3904, ff06c308,
    21878) + 94
    ff018364 printf (112a4, 21878, 0, 21896, ff068284, ff2dec08) + 5c
    00010c8c __1cMinterpthread6Fpv_0_ (0, fec7c000, 0, 0, 10c38, 0) + 54
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    ----------------- lwp# 4 / thread# 4 --------------------
    fefb0c90 strlen (ff2bdee8, feafbcf4, 4000, 73, 2e, 4000) + 50
    ff274924 PyErr_Format (ff2ebb2c, ff2bdee8, 0, 1400, 1780, ff2dec08) +
    18
    ff1feeb8 PyObject_HashNotImplemented (e4020, 0, 5000, 53bc, ff2f6ba0,
    0) + 34
    ff1f8420 PyDict_GetItem (23a50, e4020, 20000000, cb28c, ff2dec08, 0)
    + 64
    ff213a2c PyString_InternInPlace (feafbe3c, 53bc, ff2f6ba0, e4020,
    ff2f6ba0, ff2dec08) + b4
    ff1fb6b4 PyDict_SetItemString (239c0, 114a3, e3030, 21896, ff2dec08,
    1b) + 20
    00010cd8 __1cMinterpthread6Fpv_0_ (0, feafc000, 0, 0, 10c38, 0) + a0
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    ----------------- lwp# 5 / thread# 5 --------------------
    ff040154 __lwp_park (0, 0, ff06c348, 0, 0, 1) + 14
    ff02415c _flockget (ff06c348, 21878, 441b4, 0, ff06c308, 21878) + 94
    ff018364 printf (112a4, 21878, 0, 21896, ff068284, ff2dec08) + 5c
    00010c8c __1cMinterpthread6Fpv_0_ (0, fe9fc000, 0, 0, 10c38, 0) + 54
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    ----------------- lwp# 6 / thread# 6 --------------------
    ff040154 __lwp_park (0, 0, ff06c348, 0, 0, 1) + 14
    ff02415c _flockget (ff06c348, 21878, 441b4, ff29afcc, ff06c308,
    21878) + 94
    ff018364 printf (112a4, 21878, 0, 21896, ff068284, ff2dec08) + 5c
    00010c8c __1cMinterpthread6Fpv_0_ (0, fe8fc000, 0, 0, 10c38, 0) + 54
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    ----------------- lwp# 7 / thread# 7 --------------------
    ff3d7e68 ___lwp_mutex_timedlock (0, 1, ff3c3f98, ff3ee980, 2ae64,
    ff3ee268) + c
    ff3cc60c elf_bndr (ff3f1b98, 132c, ff1f0840, e3030, ff3f06d0, 0) + 28
    ff3b3904 elf_rtbndr (ff1f0840, 3d, 1, 92492400, ff2f339c, 8) + 10
    ff2e4060 ???????? (e3020, ff2f2314, 0, 0, 0, 0)
    ff1f0840 PyLong_FromLong (0, 21878, ff06c348, 21896, ff2dec08, 1b) +
    44
    00010cc8 __1cMinterpthread6Fpv_0_ (0, fe7fc000, 0, 0, 10c38, 0) + 90
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    ----------------- lwp# 8 / thread# 8 --------------------
    ff040154 __lwp_park (0, 0, ff06c348, 0, 0, 1) + 14
    ff038db0 mutex_lock_internal (ff06c348, 0, 1, 0, 10, ff06cbc0) + 5d0
    ff02415c _flockget (ff06c348, 21878, 441b4, ff29afcc, ff06c308,
    21878) + 94
    ff018364 printf (112a4, 21878, 0, 21896, ff068284, ff2dec08) + 5c
    00010c8c __1cMinterpthread6Fpv_0_ (0, fe6fc000, 0, 0, 10c38, 0) + 54
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    ----------------- lwp# 9 / thread# 9 --------------------
    ff040154 __lwp_park (0, 0, ff06c348, 0, 0, 1) + 14
    ff038db0 mutex_lock_internal (ff06c348, 0, 1, 0, 10, ff06cbc0) + 5d0
    ff02415c _flockget (ff06c348, 21878, 441b4, ff29afcc, ff06c308,
    21878) + 94
    ff018364 printf (112a4, 21878, 0, 21896, ff068284, ff2dec08) + 5c
    00010c8c __1cMinterpthread6Fpv_0_ (0, fe5fc000, 0, 0, 10c38, 0) + 54
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    ----------------- lwp# 10 / thread# 10 --------------------
    ff06a64c ???????? (21888, 42, ffffffe5, 7, ff070513, ffffffe5)
    ff0183fc printf (112a4, 21878, ff06c348, 21896, ff068284, ff2dec08)
    + f4
    00010c8c __1cMinterpthread6Fpv_0_ (0, fe4fc000, 0, 0, 10c38, 0) + 54
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    ----------------- lwp# 11 / thread# 11 --------------------
    ff040154 __lwp_park (0, 0, ff06c348, 0, 0, 1) + 14
    ff038db0 mutex_lock_internal (ff06c348, 0, 1, 0, 10, ff06cbc0) + 5d0
    ff02415c _flockget (ff06c348, 21878, 441b4, ff29afcc, ff06c308,
    21878) + 94
    ff018364 printf (112a4, 21878, 0, 21896, ff068284, ff2dec08) + 5c
    00010c8c __1cMinterpthread6Fpv_0_ (0, fe3fc000, 0, 0, 10c38, 0) + 54
    ff0400b0 _lwp_start (0, 0, 0, 0, 0, 0)
    grbgooglefan, Apr 15, 2009
    #1
    1. Advertising

  2. grbgooglefan

    Aahz Guest

    In article <>,
    grbgooglefan <> wrote:
    >
    >I have C application in which I have instantiated Python interpreter
    >in each worker thread.
    >
    >When I start the program it crashes at different places in Python code
    >but program never finishes normally.
    >
    >Can you please help me in following queries?
    >1) Can we not use Python interpreters per thread instead of having a
    >common shared Python interpreter at global level/ scope?


    Theoretically you can, but each Python interpreter shares some objects
    with others, so you still need to use the Python GIL.
    --
    Aahz () <*> http://www.pythoncraft.com/

    Why is this newsgroup different from all other newsgroups?
    Aahz, Apr 16, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vbfoo Bar
    Replies:
    1
    Views:
    339
    Benjamin Niemann
    Sep 14, 2004
  2. vishnu
    Replies:
    0
    Views:
    372
    vishnu
    Mar 31, 2007
  3. Marcin Kalicinski
    Replies:
    3
    Views:
    600
    Graham Dumpleton
    Jun 10, 2007
  4. Replies:
    9
    Views:
    719
    Rhamphoryncus
    Apr 13, 2008
  5. Casey
    Replies:
    1
    Views:
    285
    Gabriel Genellina
    May 12, 2008
Loading...

Share This Page