Hello,
I'm afraid that linuxtuples is currently not suited for multithreaded
python code.
In Python, the global-interpreter-lock is released for operations that
block. E.g. I/O ops, or a time.sleep() op.
If a thread blocks on such an op, other python threads get a chance
to use the interpreter.
In linuxtuples, the get() and read() operations will block, yet do
not relinquish the lock, causing other threads to starve. The code
below demonstates the problem.
If you comment out the conn.get(t) operation, both threads happily
execute their iterations. With the get() operation in there, the
main thread starves.
How can we fix this?
As it is, linuxtuples' usefulness under python is heavily reduced.
Bram
import sys
import os
import time
import linuxtuples
import threading
def read_from_space() :
while True :
print "#"
t=("does","not","exist")
conn.get(t)
time.sleep(0.5)
conn = linuxtuples.connect()
thread = threading.Thread(target=read_from_space)
thread.setDaemon(True)
thread.start()
while True :
print "*"
time.sleep(0.1)
--
Bram Stolk, VR Engineer SARA, Amsterdam. tel +31 20 592 3000
"Windows is a 32-bit extension to a 16-bit graphical shell for an 8-bit
operating system originally coded for a 4-bit microprocessor by a 2-bit
company that can't stand 1 bit of competition."
|