[Tutor] threading tutorial

Michael C mysecretrobotfactory at gmail.com
Thu Jun 1 13:53:34 EDT 2017


let me try that! thanks!


On Thu, Jun 1, 2017 at 10:52 AM, Jerry Hill <malaclypse2 at gmail.com> wrote:

> On Thu, Jun 1, 2017 at 11:30 AM, Michael C
> <mysecretrobotfactory at gmail.com> wrote:
> > Oh i get it alright, however in my code I have to push the W button like
> > this:
> >
> > import pyautogui
> > import time
> >
> > pyautogui.keyDown('w')
> > time.sleep(2)
> > pyautogui.keyUp('w')
>
> ...
>
> > theoretically deals with my problem, in practice though, my function
> spend
> > almost
> > all its time holding down the 'w' button, given how many miliseconds i
> need
> > it. and so it's not responsive enough
> > for this reason.
>
> From that example, it looks like you spend almost all the time
> sleeping, right?  Maybe sleep for a shorter amount of time, in a loop
> where you can check the flag?  Something like:
>
> global run_me
> time_to_sleep = 2
> time_asleep = 0
>
> pyautogui.keyDown('w')
> while run_me and (time_asleep < time_to_sleep):
>     delta = time_to_sleep/100
>     time.sleep(delta)
>     time_asleep += delta
> pyautogui.keyUp('w')
>
> That would let you check the flag more often, so you can clean up properly.
>
> --
> Jerry
>


More information about the Tutor mailing list