question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

get_gamepad seems to block

See original GitHub issue

For my application it is crucial to check if there are new events but if not, proceed with the other code. However: In order to check for new events I need to call get_gamepad which calls internal read on the device. This function seems to block until an event arrives. It would be awesome to add a nonblocking read or an option to specify all reads as nonblocking!

As always: Thanks for your library!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:7
  • Comments:12

github_iconTop GitHub Comments

6reactions
ErikOrjehagcommented, Feb 5, 2020

I added this in the _character_device() in the InputDevice class:

self._character_file = io.open(
  self._character_device_path, 'rb')
fd = self._character_file.fileno()
flag = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, flag | os.O_NONBLOCK)

And then calling this in my code:

events = devices.gamepads[0]._do_iter()

To bypass the while True loop in iter(). Not so pretty but hey, it worked for me!

I think adding this flag and also yeilding an empty array in iter() if there is no data would be a nice complete solution but I never tried it.

1reaction
Sartekcommented, Feb 15, 2019

why was the blocking parameter never added to inputs? I either need to run part of my input handling in a seperate thread or I need to edit inputs to be nonblocking. it reduces my programs fps from 3000 to about 200 with most of the time being spent waiting for inputs.get_gamepad()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Navigator.getGamepads() - Web APIs - MDN Web Docs
getGamepads () method returns an array of Gamepad objects, one for each gamepad connected to the ... Use of this feature was blocked...
Read more >
I get getGamepad warnings but I'm not using gamepads at all
I started getting getGamepad warnings in HTTP context. ... and I don't want to use gamepads at all :thinking: How to fully disable...
Read more >
Is the HTML5 Gamepad API limited to only 4 Controllers?
getGamepads (); seems to return an array of 4 undefined spots in Chrome and Edge, and an unspecified array in FireFox that still...
Read more >
Gamepad - W3C on GitHub
Axes that are drawn from a 2D input device SHOULD appear next to each ... Gamepads returned by getGamepads () MUST NOT report...
Read more >
Using Gamepads and Joysticks in JavaScript - Beej.us
Also I can't seem to get it to show another one of my joysticks at all. ... getGamepads(); for (let i = 0;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found