Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#96 stdin_reader() in parser.py causes spin lock and exception

open
nobody
None
5
2012-12-06
2010-02-16
YoHell
No

The self.parse(l) call at line 514 of parser.py causes exceptions because of incorrect number of arguments.
Also, when self.cmd._pymol.invocation.options.keep_thread_alive is True, the while loop starting at line 507 spin locks the parse thread and causes 100% cpu usage. These changes fix these bugs by calling parse in insecure mode and adding a one millisecond sleep to the parser loop.

BEFORE:
def stdin_reader(self): # dedicated thread for reading standard input
import sys
while 1:
l = sys.stdin.readline()
if l!="":
if self.nest==0:
# if we're reading embedded input on stdin
# then bypass PyMOL C code altogether
if self.layer[0].embed_sentinel!=None:
self.parse(l)
else:
self.cmd.do(l)
else:
self.cmd.do(l)
elif not self.cmd._pymol.invocation.options.keep_thread_alive:
self.cmd.quit()
self.cmd._pymol._stdin_reader_thread = None

AFTER:
def stdin_reader(self): # dedicated thread for reading standard input
import sys
while 1:
l = sys.stdin.readline()
if l!="":
if self.nest==0:
# if we're reading embedded input on stdin
# then bypass PyMOL C code altogether
if self.layer[0].embed_sentinel!=None:
self.parse(l, False) ### CHANGED LINE
else:
self.cmd.do(l)
else:
self.cmd.do(l)
elif not self.cmd._pymol.invocation.options.keep_thread_alive:
self.cmd.quit()
else: ### ADDED LINE (break out instead?)
import time
time.sleep(0.001)
self.cmd._pymol._stdin_reader_thread = None

Discussion

  • YoHell
    YoHell
    2010-02-16

    Once again I forget that sourceforge kills indent from details. Not good for python source. Trying with a comment instead.

    BEFORE:
    def stdin_reader(self): # dedicated thread for reading standard input
    import sys
    while 1:
    l = sys.stdin.readline()
    if l!=\"\":
    if self.nest==0:
    # if we\'re reading embedded input on stdin
    # then bypass PyMOL C code altogether
    if self.layer[0].embed_sentinel!=None:
    self.parse(l)
    else:
    self.cmd.do(l)
    else:
    self.cmd.do(l)
    elif not self.cmd._pymol.invocation.options.keep_thread_alive:
    self.cmd.quit()
    self.cmd._pymol._stdin_reader_thread = None

    AFTER:
    def stdin_reader(self): # dedicated thread for reading standard input
    import sys
    while 1:
    l = sys.stdin.readline()
    if l!=\"\":
    if self.nest==0:
    # if we\'re reading embedded input on stdin
    # then bypass PyMOL C code altogether
    if self.layer[0].embed_sentinel!=None:
    self.parse(l, False) ### CHANGED LINE
    else:
    self.cmd.do(l)
    else:
    self.cmd.do(l)
    elif not self.cmd._pymol.invocation.options.keep_thread_alive:
    self.cmd.quit()
    else: ### ADDED LINE (break out instead?)
    import time
    time.sleep(0.001)
    self.cmd._pymol._stdin_reader_thread = None