threading in internal spyder shell

384 views
Skip to first unread message

Guenter Ebermann

unread,
Jun 11, 2010, 5:58:22 AM6/11/10
to spyder
Hi,

Iam trying to add a python shell (and perhaps a python IDE) to
make our Bus monitoring (CAN, FlexRay, ...) Products scriptable.

At the moment I am running simple tests using spyder and I wrote a
few python testscript.

However, it seems python-threading out of a script which is started
in the internal shell of spyder does not work.

I tested this using a simple script:
It only starts a python thread and prints a text to stdout and
sleeps one second.

Starting the script in external console works.
Starting the script in internal console blocks the whole GUI.

Does the internal console run in the same thread as the Spyder GUI?
If so, would it be possible to start it in a own thread?

My problem is that I can only use internal console to use
my proretiery API of a C++-GUI which starts CPython which
starts Spyder (therfor it must run in the same process):

MFC-C++-GUI --------------------- SWIG python interface of MFC-C++ GUI
(public API)
| needs a running MFC-C++-
GUI
-> Cpython interpreter ^
| |
---> Spyder - QT4 |
| |
----------> Skript1 - thread1 updates MFC GUI
widgets
|
----------> Skript2 - thread2 updates MFC GUI
widgets

So we need the possibility to start two python skripts "parallel".
And both scripts must run in the same process as the C++-GUI to
allow access to the public python API of the GUI.

The scripts will usually process incoming bus traffic (via public API)
and change GUI elements appropriately (via public API).

Help is very much appreciated,
Thanks,
Guenter

Pierre Raybaut

unread,
Jun 11, 2010, 7:18:40 AM6/11/10
to spyder
Theading is indeed not supported in the interactive console.
Note that the interactive console will be completely replaced by the
external console in v2.0. So, I strongly recommend to use it for this
kind of work (in v1.1.0rc1 there is no difference between the
interactive console and the external console in terms of features).

Cheers,
Pierre

On Jun 11, 11:58 am, Guenter Ebermann

Guenter Ebermann

unread,
Jun 11, 2010, 1:02:54 PM6/11/10
to spyd...@googlegroups.com

Am 11.06.2010 um 13:18 schrieb Pierre Raybaut:

> Theading is indeed not supported in the interactive console.
> Note that the interactive console will be completely replaced by the
> external console in v2.0. So, I strongly recommend to use it for this
> kind of work (in v1.1.0rc1 there is no difference between the
> interactive console and the external console in terms of features).

Thanks for the info. We are trying to use 1.1.0rc1 as suggested.
But if I understand you correctly, this also means that the shell runs
the python interpreter in a new process.
Therefor the advantage that the already running python interpreter
is used is lost. This would be needed in my project to be able to access
the currently running instance of the calling program.

In the opposit, trying to reach the runtime of the calling program from
an external shell will result in reloading of the undelying dlls (data
parts) and no access to the already running instance.

--Guenter

Pierre Raybaut

unread,
Jun 11, 2010, 4:37:12 PM6/11/10
to spyder
1. Regarding the interactive console, it is actually *not*
multithreaded, as I wrote above. But the reason was that the user had
to be able to execute GUI-based apps in this console, and as you
certainly know, the GUI-related stuff must be running in the same
thread: Spyder itself being GUI-based, it must be the same thread as
the main window... Now that the external console is going to replace
the interactive console (and it's perfectly able to run GUI-based
apps), I could rewrite the interactive console so that it may be
multithreaded -hence fitting your needs.

2. When opening a Python/IPython interpreter in the external console,
it's also possible to send data from Spyder's process through a simple
pickle. That is not implemented programmaticaly but it could be easily
done.

Pierre

On 11 juin, 19:02, Guenter Ebermann <guenter.eberm...@googlemail.com>
wrote:

Pierre Raybaut

unread,
Jun 11, 2010, 5:07:35 PM6/11/10
to spyder
Note that the more I think about it, the more I'm convinced that it
could be a good thing to implement a multithreaded internal console
(but non GUI capable... which is not a problem thanks to interactivity-
related recent developments on the external console).

And it should not be so long to do... I'll see what I can do.

Pierre

Guenter Ebermann

unread,
Jul 6, 2010, 1:16:41 PM7/6/10
to spyder

Hi Pierre,

Thank you very much for your help. We plan to integrate spyderlib into
our next product version. We use it as source code editor and for
debugging and as shell to reach the internal C-data structures
(wrapped
with SWIG to pyhton API).

On 11 Jun., 22:37, Pierre Raybaut <pierre.rayb...@gmail.com> wrote:
> 2. When opening a Python/IPython interpreter in the external console,
> it's also possible to send data from Spyder's process through a simple
> pickle. That is not implemented programmaticaly but it could be easily
> done.

Yes, but you do not have access out of the box. One must use IPC or
such mechanisms to reach the other process ...

On 11 Jun., 23:07, Pierre Raybaut <pierre.rayb...@gmail.com> wrote:
> Note that the more I think about it, the more I'm convinced that it
> could be a good thing to implement a multithreaded internal console
> (but non GUI capable... which is not a problem thanks to interactivity-
> related recent developments on the external console).

Yes. A thread capable external console is the only requirement which
is needed from my side and not actually implemented. If possible I can
start the implementation (based on spyder 1.2.1?) if you can further
guide me.
For now I do not really understand where the limitiation in the
current implementation is. However I already reviewed a lot of source
of spyderlib/ipython source already.

Guenter

Pierre Raybaut

unread,
Jul 6, 2010, 4:33:14 PM7/6/10
to spyder
On Jul 6, 7:16 pm, Guenter Ebermann <guenter.eberm...@googlemail.com>
wrote:
> > Note that the more I think about it, the more I'm convinced that it
> > could be a good thing to implement a multithreaded internal console
> > (but non GUI capable... which is not a problem thanks to interactivity-
> > related recent developments on the external console).
>
> Yes. A thread capable external console is the only requirement which
> is needed from my side and not actually implemented. If possible I can
> start the implementation (based on spyder 1.2.1?) if you can further
> guide me.
> For now I do not really understand where the limitiation in the
> current implementation is. However I already reviewed a lot of source
> of spyderlib/ipython source already.
>
> Guenter

Actually it's already done :)
I've implemented a multithreaded internal console in Spyder v2.0.
You may try the version available in the Mercurial repository:
http://code.google.com/p/spyderlib/source/checkout

Note that the internal console is hidden by default (you'll have to
check it in "View" menu) because it is mainly intended for internal
debug.

(Spyder v2.0 is still at an early stage of development -I'm currently
working on v2.0.0alpha2- but it's already quite stable -- I'm using it
almost everyday as a production version)

Pierre

Guenter Ebermann

unread,
Jul 7, 2010, 7:51:51 AM7/7/10
to spyder
Hi Pierre,

On 6 Jul., 22:33, Pierre Raybaut <pierre.rayb...@gmail.com> wrote:
> Actually it's already done :)
> I've implemented a multithreaded internal console in Spyder v2.0.
> You may try the version available in the Mercurial repository:http://code.google.com/p/spyderlib/source/checkout

Perfect. I will try it out as soon as possible and give feedback.

Guenter
Reply all
Reply to author
Forward
0 new messages