[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2015-05-24 Thread Jackmoo

Jackmoo added the comment:

Hi there, recently I also encounter this in windows(7), and my python program 
occasionally crash and the windows pops 'appcrash' message with tcl8.5.dll 
error c05 (access violation).

And this end up related to thread safe problem described as above. Since in my 
program, I have to build the tkinter UI in another thread (main thread was 
occupied by other module which blocking), so I can't follow the 'build UI in 
main thread' solution. My work around is, add a handler which using .after() 
and get_nowait() to call itself periodically to handle the command in queue.

def commandQueueHandler(self):
try:
while 1:
your_command = self.textCommandQueue.get_nowait()
if your_command is not None:
# execute the command 
self.Text.update_idletasks()
except Queue.Empty:
pass
self.Text.after(100, self.commandQueueHandler)

Once this method is triggered, just build another thread to put() command in 
textCommandQueue, then it will be executed periodically.
One thing that should mention is the update_idletasks() should be added after 
each command execution, otherwise the UI refresh will be slower then expected. 
(in my case, the scrolling of Text widge is a bit 'sticky' when I pull it. 
After adding update_idletasks(), it becomes smoother.)

TL:DR,
If you have to run tkinter UI in another thread, add a queue and self-called 
method with after() and get_nowait() in UI thread to handle the queue. If you 
want to send command to UI at other thread, just put() the command in the queue 
of UI thread.

--
nosy: +Jackmoo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2015-05-24 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Thanks for the report.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2013-03-08 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I have somewhat arbitrary selected #16823 as the issue turned into a tkinter 
and threads doc issue. I added a note there about mentioning the use of queue.

--
resolution:  - duplicate
status: open - closed
superseder:  - Python quits on running tkinter code with threads

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2011-01-28 Thread Scott M

Scott M scott.m...@comcast.net added the comment:

OK, now all calls to Tkinter are funneled to a single thread, through a queue. 
(Technically there are two threads in Tkinter - one is parked in .mainloop(), 
the other makes a call to Canvas.create_line and a call to Label.config.) 
Different crash, but still a crash. This one seems to be mostly consistent; see 
below and new attached code.

If you're going to tell me that Tkinter simply can never be called by any 
thread other than the one animating mainloop - in other words, Tkinter calls 
are only safe within Tkinter callbacks like a Button's command function - then 
please suggest an alternative library that is sturdier. There's nothing I can 
do about the fact that multiple threads produce independent data that has to go 
onto a single graph.

Exception in thread Thread-1:
Traceback (most recent call last):
  File C:\Python27\lib\threading.py, line 530, in __bootstrap_inner
self.run()
  File C:\Documents and 
Settings\mayos\Desktop\PMT2\MyProjects\TkinterCrash.py, line 68, in run
self.graph.create_line(element[0], element[1], element[2], element[3])
  File C:\Python27\lib\lib-tk\Tkinter.py, line 2201, in create_line
return self._create('line', args, kw)
  File C:\Python27\lib\lib-tk\Tkinter.py, line 2189, in _create
*(args + self._options(cnf, kw
ValueError: invalid literal for int() with base 10: 'None'

But once I got:

Exception in thread Thread-1:
Traceback (most recent call last):
  File C:\Python27\lib\threading.py, line 530, in __bootstrap_inner
self.run()
  File C:\Documents and 
Settings\mayos\Desktop\PMT2\MyProjects\TkinterCrash2.py, line 68, in run
self.graph.create_line(element[0], element[1], element[2], element[3])
  File C:\Python27\lib\lib-tk\Tkinter.py, line 2201, in create_line
return self._create('line', args, kw)
  File C:\Python27\lib\lib-tk\Tkinter.py, line 2189, in _create
*(args + self._options(cnf, kw
TclError: can not find channel named Nonefile13cad48

--
Added file: http://bugs.python.org/file20576/TkinterCrash2.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2011-01-28 Thread Scott M

Scott M scott.m...@comcast.net added the comment:

Alright. More digging turned up the Tkinter after function, aka WM_TIMER for 
Windowy people like me, and that plus a nonblocking queue get() gets all my 
drawing operations back into the mainLoop() thread. VoilĂ , no more crashes.

Let me suggest that page one, sentence one of any Tkinter documentation should 
begin Tkinter is not thread safe, with a link to an example of after() and 
nonblocking get(). I've changed the component to Documentation. This would save 
a few days for poor sods like me -- I'm used to low level Windows C++ GUI work, 
where any thread can call any SDK function at any time, and Windows sorts it 
all out. 

Having to force everything into a single thread, and then poll for my data 
(*GAG*), is something I thought died in the 80's. Is anyone looking at thread 
safe GUI libraries?

--
assignee:  - docs@python
components: +Documentation -Tkinter
nosy: +docs@python

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2011-01-28 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

There are other gui libraries with Python interfaces that you can look at. I 
agree that something in doc about how to feed data from multiple threads would 
be nice.

--
nosy: +terry.reedy
type: crash - behavior
versions: +Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2011-01-27 Thread Scott M

New submission from Scott M scott.m...@comcast.net:

Running on dual core Windows XP. 

The function should draw a parabolicish shape for each click on launch. But if 
you click Launch over and over, very fast, you get bizarre crashes instead: 
Python.exe has encoutered a problem, yadda. tcl85.dll. It rarely takes many 
clicks.

Apologies for the coding style; this has been hacked down from a larger app.

In the console window:

Exception in thread Thread-5:
Traceback (most recent call last):
  File C:\Python27\lib\threading.py, line 530, in __bootstrap_inner
self.run()
  File C:\Documents and Settings\mayos\Desktop\PMT2\MyProjects\TkinterCrash.py
, line 47, in run
self.app.arrival_122((self.target, y, z))
  File C:\Documents and Settings\mayos\Desktop\PMT2\MyProjects\TkinterCrash.py
, line 100, in arrival_122
self.label.config(text= str(message[0])+   + str(message[1]))
  File C:\Python27\lib\lib-tk\Tkinter.py, line 1202, in configure
return self._configure('configure', cnf, kw)
  File C:\Python27\lib\lib-tk\Tkinter.py, line 1193, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: invalid command name source C:/Python27/tcl/tk8.5/menu.tcl

Exception in thread Thread-4:
Traceback (most recent call last):
  File C:\Python27\lib\threading.py, line 530, in __bootstrap_inner
self.run()
  File C:\Documents and Settings\mayos\Desktop\PMT2\MyProjects\TkinterCrash.py
, line 47, in run
self.app.arrival_122((self.target, y, z))
  File C:\Documents and Settings\mayos\Desktop\PMT2\MyProjects\TkinterCrash.py
, line 125, in arrival_122
self.graph.create_line(self.trackCoordinates[tn], new_yz)
  File C:\Python27\lib\lib-tk\Tkinter.py, line 2201, in create_line
return self._create('line', args, kw)
  File C:\Python27\lib\lib-tk\Tkinter.py, line 2189, in _create
*(args + self._options(cnf, kw
TclError: invalid command name line

Also saw:
  File C:\Python27\lib\lib-tk\Tkinter.py, line 2201, in create_line
return self._create('line', args, kw)
  File C:\Python27\lib\lib-tk\Tkinter.py, line 2189, in _create
*(args + self._options(cnf, kw
TclError: bad option 665.44997: must be addtag, bbox, bind, canvasx, 
canvasy, cget, configure, coords, create, dchars, delete, dtag, find, focus, 
gettags, icursor, index, insert, itemcget, itemconfigure, lower, move, 
postscript, raise, scale, scan, select, type, xview, or yview

--
components: Tkinter
files: TkinterCrash.py
messages: 127201
nosy: PythonInTheGrass
priority: normal
severity: normal
status: open
title: Crash, 2.7.1, Tkinter and threads and line drawing
type: crash
versions: Python 2.7
Added file: http://bugs.python.org/file20549/TkinterCrash.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2011-01-27 Thread Brian Curtin

Changes by Brian Curtin cur...@acm.org:


--
nosy: +brian.curtin

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2011-01-27 Thread Scott M

Scott M scott.m...@comcast.net added the comment:

To make this more interesting, I'm trying to push for adoption of Python at a 
scripting tool where I work, and I uncovered this crasher in example code I was 
about to hand out, under the heading of look how easy Python is. For obvious 
reasons I'm holding off on handing out the example; I won't get far selling 
Python if it crashes when drawing lines... if this is a result of something 
boneheaded I did, please slap me upside the head ASAP. Conversely if there's a 
quick fix possible, that will speed Python adoption where I work... thanks.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11029] Crash, 2.7.1, Tkinter and threads and line drawing

2011-01-27 Thread Christoph Gohlke

Christoph Gohlke cgoh...@uci.edu added the comment:

Tkinter is not thread safe. You are changing UI elements from a thread that is 
not the main thread. Use a Queue as described at 
http://effbot.org/zone/tkinter-threads.htm.

--
nosy: +cgohlke

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11029
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com