473,785 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python threading and timing

hello

I'm writing a Python application for live music performance/improivsation,
using csound as the synthesis engine, and Python for compositional
algorithms, GUI and control.

I creating several threads:
one for GUI
one for csound,
one for a timed queue (timed automation events),
one for communication with a tcp based sensor interface.

My threads do not share data,
I use threads merely to enable several processes to run in paralell.
I think I do not need to use locks to control threads in this case,
but I'm not sure (?)

Also, I wonder what method I should be using to get a precise timing
in my automation thread (acting as a sequencer).

I've attached two simple examples of different ways I could implement threads.
The only task in these examples is to generate timed counters, but the
general procedure would be the same for more complex timed tasks.
One example uses time.sleep() to release a thread's interpreter lock,
and at the same time provide the time interval until the next
iteration.
The other example uses a thread event wait() call.

It seems that the example using wait() does not provide the same
precision as time.sleep() does (the counters does not sync, e.g. a
counter with a time interval of 0.1 does not count 10 times as fast as
a counter with a time interval of 1 second.

Any insights on how to do this the best way (thread safety and time
precision) would be greatly appreciated.

best
Oeyvind Brandtsegg

Oct 1 '06 #1
2 2552
Dennis Lee Bieber a écrit :
On Sun, 1 Oct 2006 22:28:10 +0200, "Oeyvind Brandtsegg"
<ob******@gmail .comdeclaimed the following in comp.lang.pytho n:
>Also, I wonder what method I should be using to get a precise timing
in my automation thread (acting as a sequencer).
Use a real-time OS (which neither M$ Windows nor Linux/UNIX claim to
be).

All non-deterministic, multi-tasking, OS's (like Windows, Linux,
Solaris, AmigaOS) only guarantee that, for example, a sleep() call will
not return /before/ the time specified. There is no specification for
how much time /over/ the duration actually takes place.

And setting the task priority into the Windows "real-time" category
is not sufficient -- I had an application that had to put out data on
six pins of the parallel port (acting as three discrete RS-422 style
balanced signals) in time with a (1KHz, as I recall) clock signal coming
in on another pin of the parallel port. The data was still getting
glitches every ~256 clocks as the OS did something in the background.
(the application was written in VC++6, and even disabled the GUI during
the data output operation.
+++

realtime OSes != high level priority threads

And for a sound production using a sequencer, it looks like to need real
realtime.
And dont use Python threads for realtime multithreading, even on a
realtime OS (because of the GIL - Global Interpreter Lock).

May use Python for some -non realtime- parts, but I would not use any
scripting language (not specific to Python) for real-time work (prefer
C, ADA, maybe Java with ad-hoc extensions).

You may go to Python by writing a Python C extension module (doing
realtime work on its own - but never relying on python GIL in critical
times), communicating with normal python scripts (shared memory...
things which dont need the GIL if possible).

A+

Laurent.
Oct 2 '06 #2
In article <ef**********@u psn250.cri.u-psud.fr>,
Laurent Pointal <la************ *@limsi.frwrote :
Oct 4 '06 #3

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

Similar topics

23
2499
by: Antoon Pardon | last post by:
I have had a look at the signal module and the example and came to the conclusion that the example wont work if you try to do this in a thread. So is there a chance similar code will work in a thread? -- Antoon Pardon
0
921
by: Russell Warren | last post by:
I've got a case where I need to tweak the implementation of a default python library due to what I consider to be an issue in the library. What is the best way to do this and make an attempt to remain compatible with future releases? My specific problem is with the clock used in the threading.Event and threading.Timer. It currently uses time.time, which is affected by changes in system time. eg: if you change the system clock somehow...
7
6424
by: silverburgh.meryl | last post by:
Hi, I am using timeit to time a global function like this t = timeit.Timer("timeTest()","from __main__ import timeTest") result = t.timeit(); But how can i use timeit to time a function in a class? class FetchUrlThread(threading.Thread):
7
2428
by: Protocol | last post by:
Hello all Is Python suitable for building a multi-track midi sequencer (with a gui), that would run on windows / mac ? I fail to find sufficient information on this, being a newbie and all. Furthermore, i found references on Python not being really able of multi-threading, that further adds to the confusion. Please assist.
0
9484
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.