473,387 Members | 1,476 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems with threading in embedded Python

Hi all,

I hope this hasn't been brought up before, but if it did i missed it, so
bear with me please :)
anyway, i'm trying to embed Python into a C program. A sample python
syript i want to run is as follows:

---SNIP---
import time
import threading

go_on = 1
t = 0

def ProcessMessage():
print "... ProcessMessage"

def Main():
global go_on
print "... Main"
while go_on:
ProcessMessage ()
print "... ... ",
time.sleep (0.2)

def Setup():
global t
print "... Setup"
t = threading.Thread (None, Main)
t.start ()
# t.join (0)
# print t.isAlive()

def Shutdown():
global go_on, t
go_on = 0
t.join ()
print "... Shutdown"

---SNIP---

I call "Setup" from C, which should create a new thread which should
enter the loop in Main. well, it doesn't :)

It prints "... Setup" and does nothing. when i call Shutdown from C, it
prints "... Main" , followed by "... Shutdown", and exits...

So it seems to me the python interpreter wants to run the seperate
thread, but doesn't get time from the scheduler (is that the thing about
100 opcodes?)
How can i handle this problem? Do I need to wrap all the Py_Stuff()
into its own thread? do i need artificial python code that only serves
the purpose of piling up enough opcodes so that the Main() thread gets
eventually called?

I hope you can help me, if you need more code (f.ex. the C-code ), i
will post more :)
(basically I modified the run_func.cc file from the docs, added
PyEval_InitThreads() and monkeyed around with GIL and
Acquire/ReleaseLock, but so far i had no luck :)

Cheers, Nico
Aug 17 '07 #1
1 1396
In article <ma***************************************@python. org>,
Nico Blodow <ni********@gmx.netwrote:
>
I hope this hasn't been brought up before, but if it did i missed it,
so bear with me please :) anyway, i'm trying to embed Python into a C
program. A sample python syript i want to run is as follows:
Looks like nobody here wants to touch this, maybe try
http://mail.python.org/mailman/listinfo/capi-sig
--
Aahz (aa**@pythoncraft.com) <* http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it." --Dijkstra
Aug 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Wenning Qiu | last post by:
I am researching issues related to emdedding Python in C++ for a project. My project will be running on an SMP box and requires scalability. However, my test shows that Python threading has very...
1
by: freesteel | last post by:
I am trying to run a python programme embedded from C++. I want to run the same python code concurrently in several threads. I read the manual on embedding, especially chapter 8, and searched for...
1
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket)....
19
by: Ant | last post by:
Hi all, I have a question on PyParsing. I am trying to create a parser for a hierarchical todo list format, but have hit a stumbling block. I have parsers for the header of the list (title and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.