473,387 Members | 1,757 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.

After PyRun_File the Thread stops

1
I am implementing python in a application that loads the following script:

Expand|Select|Wrap|Line Numbers
  1. import time
  2. from threading import Thread
  3.  
  4.  
  5. class MyThread(Thread):
  6.     def __init__(self):
  7.         Thread.__init__(self)
  8.  
  9.     def run(self):
  10.         i = 0
  11.         while i < 100:
  12.             print("teste " + str(i))
  13.             i += 1
  14.             time.sleep(1)
  15.  
  16.  
  17.  
  18. test = MyThread()
  19. test.start()
I was using WingIDE when I coded this test and it worked fine, the problem is that when I execute it from my application. All it executes is the print("teste 0"). (the application doesn't stop responding, but the thread doesn't work like it should)

Here is my C code:
Expand|Select|Wrap|Line Numbers
  1. FILE *f = fopen("main.py", "r");
  2.  
  3.     if (!f)
  4.         return;
  5.  
  6.     Py_Initialize();
  7.     PyObject* main_module = PyImport_AddModule("__main__");
  8.     PyObject* main_dict = PyModule_GetDict(main_module);
  9.  
  10.     PyRun_File(f, "main.py", Py_file_input, main_dict, main_dict);

Thank you for your time.

Yours,
Aug 4 '10 #1
0 974

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Steve | last post by:
Hi, I have a multithreaded python script that collects some data periodically and populates it into a database. For some reason, one of the thread keeps stopping after running for some while and...
15
by: Phil | last post by:
Hi, I've a simple asp.net page with one button. In the OnClick event, I want to create a thread that will perform a long runninf task. Here is a sample code in the OnClick Thread t = new...
4
by: Todd | last post by:
I have an ASP.NET application and I would like to have some code run on the server automatically once a day at a specified time. I create a timer thread to call a simple callback in the...
2
by: jt | last post by:
Below is the code with the problem (it is just one form): When you run the code, you hear a beep every second, the beep is on a new thread. When you push the button 100 forms are opend, the beep...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.