I'm assuming here that window.flip() blocks with vsync on, which may
well not be true. If it doesn't block then I would try adding clock
sleeps to minimize CPU instead of threads or processes.

-Casey

On Fri, Jan 22, 2010 at 10:16 AM, Casey Duncan <[email protected]> wrote:
> If you don't want to go the C route, this seems like a good
> opportunity to use the multiprocessing module (new in 2.6). With that
> you can setup a process to poll your external data source and put it
> in a queue to feed the process that draws to the screen.
>
> Also, another thought would be to just use you original method and try
> to minimize the CPU used. If you instantiate your own
> pyglet.clock.Clock() you can use its high-res sleep() method to rest
> the CPU in your polling loop for short intervals. The trouble with
> this is that with vsync on, your polling loop may skip some cycles
> while waiting for the window to flip(), depending on the timing. This
> shouldn't be a problem with the first solution, then you only have to
> worry about OS scheduling irregularities.
>
> -Casey
>
> On Fri, Jan 22, 2010 at 3:36 AM, Florian Bösch <[email protected]> wrote:
>> That's one of those typical I/O problems where I'd go and spawn a
>> thread in which I'd call a C function which operates a while loop at
>> 1khz and sleeps inbetween, then pushes its results to an output queue.
>>
>> On Jan 19, 4:52 am, Prantik <[email protected]> wrote:
>>> Hi there,
>>>
>>> I have some external experimental hardware providing data to my pyglet
>>> app in real-time (device access with ctypes), and it'd like to poll it
>>> for data at 1000Hz. Currently, my implementation is with a while loop
>>> in __main__ and manual ticks and flips, which works great, but of
>>> course thrashes CPU. I just need it to run at 1KHz, but my while loop
>>> runs at 600KHz, with each iteration checking my hardware for new data.
>>> I'm managing my ticks and framerate with time.time() to get a very
>>> nice constant 30.00 fps from the HUD meter.
>>>
>>> To try to get this speed and CPU util down to something between 1 &
>>> 10KHz, I've tried implementing this with the standard schedule and
>>> app.run() framework, but my problem is that schedule_interval has
>>> resolution only as good as my framerate, which is 60Hz max with vsync
>>> on and 500Hz with it off (i.e. fullscreen fps) along with unsightly
>>> shearing.
>>>
>>> I've thought about using the EventLoop class and overriding the idle()
>>> function, as that seems like it would let me evaluate code at much
>>> higher rates than framerate with vsync on (but less than while), and
>>> tick and flip when I need to (e.g. to get 30 fps), but a) you
>>> suggested that I not, being a n00b, and b) I don't know where to
>>> start, nor do I have any examples..
>>>
>>> Please help.
>>>
>>> Thanks,
>>> Prantik
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "pyglet-users" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group at 
>> http://groups.google.com/group/pyglet-users?hl=en.
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to