Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetConsoleMode throws an error when locust is run from Jenkins Powershell #1654

Closed
jasuomi opened this issue Dec 10, 2020 · 9 comments · Fixed by #1657
Closed

SetConsoleMode throws an error when locust is run from Jenkins Powershell #1654

jasuomi opened this issue Dec 10, 2020 · 9 comments · Fixed by #1657
Labels

Comments

@jasuomi
Copy link

jasuomi commented Dec 10, 2020

Describe the bug

Error message is printed out to console right after the test is started in Jenkins and job fails on exit code 2 even actual test passes. We have run locust performance tests over a year on Jenkins without similar problem. Tests started to fail recently after we updated Python and Locustio versions to latest. Locust test run without a problem if it is started on Windows desktop Powershell (or cmd).

Expected behavior

Locust tests should run on CI as they run on local machine.

Actual behavior

Error "pywintypes.error: (6, 'SetConsoleMode', 'The handle is invalid.')" is printed out to console right after the test is started in Jenkins and job fails on exit code 2 even actual test passes.

Steps to reproduce

from locust import User, task, between


class MyUser(User):
    @task
    def my_task(self):
        print("executing my_task")

    wait_time = between(0.5, 10)

Start command
locust -f .\locust_test.py --headless --run-time 3

Console from Jenkins:

[Locust_test] $ powershell.exe -NonInteractive -ExecutionPolicy Bypass -File C:\Users\locust\AppData\Local\Temp\jenkins11138277147510956709.ps1
[2020-12-10 19:13:09,846] robot-vm/INFO/locust.main: Run time limit set to 3 seconds
[2020-12-10 19:13:09,847] robot-vm/INFO/locust.main: Starting Locust 1.4.1
[2020-12-10 19:13:09,847] robot-vm/INFO/locust.runners: Spawning 1 users at the rate 1 users/s (0 users already running)...
[2020-12-10 19:13:09,847] robot-vm/INFO/locust.runners: All users spawned: MyUser: 1 (1 total running)
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
  File "c:\python39\lib\site-packages\locust\input_events.py", line 89, in input_listener_func
    poller = get_poller()
  File "c:\python39\lib\site-packages\locust\input_events.py", line 81, in get_poller
    return WindowsKeyPoller()
  File "c:\python39\lib\site-packages\locust\input_events.py", line 47, in __init__
    self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
pywintypes.error: (6, 'SetConsoleMode', 'The handle is invalid.')
2020-12-10T17:13:09Z <Greenlet at 0x19066ffdd00: input_listener_func> failed with error

 Name                                                          # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                         0     0(0.00%)  |       0       0       0       0  |    0.00    0.00

[2020-12-10 19:13:09,855] robot-vm/CRITICAL/locust.main: Unhandled exception in greenlet: <Greenlet at 0x19066ffdd00: input_listener_func>
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
  File "c:\python39\lib\site-packages\locust\input_events.py", line 89, in input_listener_func
    poller = get_poller()
  File "c:\python39\lib\site-packages\locust\input_events.py", line 81, in get_poller
    return WindowsKeyPoller()
  File "c:\python39\lib\site-packages\locust\input_events.py", line 47, in __init__
    self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
pywintypes.error: (6, 'SetConsoleMode', 'The handle is invalid.')
 Name                                                          # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                         0     0(0.00%)  |       0       0       0       0  |    0.00    0.00

[2020-12-10 19:13:12,486] robot-vm/INFO/locust.main: Time limit reached. Stopping Locust.
[2020-12-10 19:13:12,486] robot-vm/INFO/locust.runners: Stopping 1 users
[2020-12-10 19:13:12,487] robot-vm/INFO/locust.runners: 1 Users have been stopped, 0 still running
[2020-12-10 19:13:12,487] robot-vm/INFO/locust.main: Running teardowns...
[2020-12-10 19:13:12,487] robot-vm/INFO/locust.main: Shutting down (exit code 2), bye.
[2020-12-10 19:13:12,487] robot-vm/INFO/locust.main: Cleaning up runner...
 Name                                                          # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                         0     0(0.00%)  |       0       0       0       0  |    0.00    0.00

Response time percentiles (approximated)
 Type     Name                                                              50%    66%    75%    80%    90%    95%    98%    99%  99.9% 99.99%   100% # reqs
--------|------------------------------------------------------------|---------|------|------|------|------|------|------|------|------|------|------|------|
--------|------------------------------------------------------------|---------|------|------|------|------|------|------|------|------|------|------|------|

executing my_task
Build step 'PowerShell' marked build as failure
Archiving artifacts
Finished: FAILURE

REST API
Jenkins 2.249.3

Console from local PC's Powershell

PS C:\workspace\tmp> locust -f .\locust_test.py --headless --run-time 3
[2020-12-10 18:55:07,816] WL313558/INFO/locust.main: Run time limit set to 3 seconds
[2020-12-10 18:55:07,816] WL313558/INFO/locust.main: Starting Locust 1.4.1
[2020-12-10 18:55:07,816] WL313558/INFO/locust.runners: Spawning 1 users at the rate 1 users/s (0 users already running)...
[2020-12-10 18:55:07,816] WL313558/INFO/locust.runners: All users spawned: MyUser: 1 (1 total running)
 Name                                                          # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                         0     0(0.00%)  |       0       0       0       0  |    0.00    0.00

executing my_task
 Name                                                          # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                         0     0(0.00%)  |       0       0       0       0  |    0.00    0.00

executing my_task
[2020-12-10 18:55:10,512] WL313558/INFO/locust.main: Time limit reached. Stopping Locust.
[2020-12-10 18:55:10,513] WL313558/INFO/locust.runners: Stopping 1 users
[2020-12-10 18:55:10,513] WL313558/INFO/locust.runners: 1 Users have been stopped, 0 still running
[2020-12-10 18:55:10,513] WL313558/INFO/locust.main: Running teardowns...
[2020-12-10 18:55:10,513] WL313558/INFO/locust.main: Shutting down (exit code 0), bye.
[2020-12-10 18:55:10,513] WL313558/INFO/locust.main: Cleaning up runner...
 Name                                                          # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                         0     0(0.00%)  |       0       0       0       0  |    0.00    0.00

Response time percentiles (approximated)
 Type     Name                                                              50%    66%    75%    80%    90%    95%    98%    99%  99.9% 99.99%   100% # reqs
--------|------------------------------------------------------------|---------|------|------|------|------|------|------|------|------|------|------|------|
--------|------------------------------------------------------------|---------|------|------|------|------|------|------|------|------|------|------|------|

Environment

  • OS: Windows 10
  • Python version: 3.9.1
  • Locust version: 1.4.1
@jasuomi jasuomi added the bug label Dec 10, 2020
@cyberw
Copy link
Collaborator

cyberw commented Dec 10, 2020

I think this is related to keyboard input handling. Can you have a look @DennisKrone ? Probably we should just catch and ignore this error. Might want to output a log message about keyboard input being disabled when it happens as well.

For now, only workaround is going back to a pre 1.4 version.

@1183746881
Copy link

The same to you,uers can not work when it happened.
python:3.7 locust:1.4.1
[2020-12-11 15:53:00,895] lep/INFO/locust.main: Starting web interface at http://0.0.0.0:8089 (accepting connections from all network interfaces)
[2020-12-11 15:53:00,901] lep/INFO/locust.main: Starting Locust 1.4.1
Traceback (most recent call last):
File "src\gevent\greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
File "C:\Users\lep\AppData\Roaming\Python\Python37\site-packages\locust\input_events.py", line 89, in input_listener_func
poller = get_poller()
File "C:\Users\lep\AppData\Roaming\Python\Python37\site-packages\locust\input_events.py", line 81, in get_poller
return WindowsKeyPoller()
File "C:\Users\lep\AppData\Roaming\Python\Python37\site-packages\locust\input_events.py", line 47, in init
self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
pywintypes.error: (6, 'SetConsoleMode', '句柄无效。')
2020-12-11T07:53:00Z <Greenlet at 0x24797943908: input_listener_func> failed with error

[2020-12-11 15:53:00,912] lep/CRITICAL/locust.main: Unhandled exception in greenlet: <Greenlet at 0x24797943908: input_listener_func>
Traceback (most recent call last):
File "src\gevent\greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
File "C:\Users\lep\AppData\Roaming\Python\Python37\site-packages\locust\input_events.py", line 89, in input_listener_func
poller = get_poller()
File "C:\Users\lep\AppData\Roaming\Python\Python37\site-packages\locust\input_events.py", line 81, in get_poller
return WindowsKeyPoller()
File "C:\Users\lep\AppData\Roaming\Python\Python37\site-packages\locust\input_events.py", line 47, in init
self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
pywintypes.error: (6, 'SetConsoleMode', '句柄无效。')

@heyman
Copy link
Member

heyman commented Dec 11, 2020

@cyberw & @DennisKrone:
Maybe it would make sense to add a command line flag that turns on the keyboard controls? It would avoid fatal errors when running in unknown environments. Also, it would avoid causing problems for people accidentally pressing the keybinding unaware of their existence.

@cyberw
Copy link
Collaborator

cyberw commented Dec 11, 2020

@cyberw & @DennisKrone:
Maybe it would make sense to add a command line flag that turns on the keyboard controls? It would avoid fatal errors when running in unknown environments. Also, it would avoid causing problems for people accidentally pressing the keybinding unaware of their existence.

We considered adding that when implementing it, but I think it is better to just fail and (maybe) log when it has failed to initialize. There should never be any fatal errors, so there should be no need to work around that (once we fix this issue).

We could of course make it opt-in, but the list of parameters is already getting very long, and I think keeping it simple is just as important :)

@heyman
Copy link
Member

heyman commented Dec 11, 2020

We could of course make it opt-in, but the list of parameters is already getting very long, and I think keeping it simple is just as important :)

Ok 👍

One thing I've thought about is to implement a fully fledged terminal GUI using Urwid (https://github.com/urwid/urwid), similar to somthing like htop. However, that would require quite a large development effort from someone.

@cyberw
Copy link
Collaborator

cyberw commented Dec 11, 2020

Can you try with latest master @jasuomi or @1183746881 ?

@leibson
Copy link

leibson commented Feb 16, 2022

I realize it's 2 years later, but now I am seeing this error when I did not used to.

I'm using the latest version of locust (2.8.2), running on a Gitlab runner.

Python version is 3.10.0.

Addendum: as with the original poster, when I run from the command line, no problem at all; runs fine.
Also, I tried various older versions of locust, but they either gave the same results, or the very old versions were not compatible with my code.

How do I even start to troubleshoot this?

Here is my stack-trace:

[2022-02-15 20:50:56,951] BuildAgent5/INFO/locust.main: Run time limit set to 5 seconds
[2022-02-15 20:50:56,953] BuildAgent5/INFO/locust.main: Starting Locust 1.5.3     <------ I got it with 2.8.2 as well.  -------
[2022-02-15 20:50:56,954] BuildAgent5/INFO/locust.runners: Spawning 1 users at the rate 1 users/s (0 users already running)...
[2022-02-15 20:50:56,955] BuildAgent5/INFO/locust.runners: All users spawned: StreamTransmitter: 1 (1 total running)
Traceback (most recent call last):
  File "src\\gevent\\greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "C:\GitLab-Runner\builds\9ceD5xZA\0\qa\engine-automation\engine-load-tests\venv\lib\site-packages\locust\input_events.py", line 92, in input_listener_func
    poller = get_poller()
  File "C:\GitLab-Runner\builds\9ceD5xZA\0\qa\engine-automation\engine-load-tests\venv\lib\site-packages\locust\input_events.py", line 84, in get_poller
    return WindowsKeyPoller()
  File "C:\GitLab-Runner\builds\9ceD5xZA\0\qa\engine-automation\engine-load-tests\venv\lib\site-packages\locust\input_events.py", line 48, in __init__
    self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
pywintypes.error: (6, 'SetConsoleMode', 'The handle is invalid.')
2022-02-15T20:50:56Z <Greenlet at 0x18b39eecca0: input_listener_func> failed with error
 Name                                                          # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                         0     0(0.00%)  |       0       0       0       0  |    0.00    0.00
[2022-02-15 20:50:56,980] BuildAgent5/CRITICAL/locust.main: Unhandled exception in greenlet: <Greenlet at 0x18b39eecca0: input_listener_func>
Traceback (most recent call last):
  File "src\\gevent\\greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "C:\GitLab-Runner\builds\9ceD5xZA\0\qa\engine-automation\engine-load-tests\venv\lib\site-packages\locust\input_events.py", line 92, in input_listener_func
    poller = get_poller()
  File "C:\GitLab-Runner\builds\9ceD5xZA\0\qa\engine-automation\engine-load-tests\venv\lib\site-packages\locust\input_events.py", line 84, in get_poller
    return WindowsKeyPoller()
  File "C:\GitLab-Runner\builds\9ceD5xZA\0\qa\engine-automation\engine-load-tests\venv\lib\site-packages\locust\input_events.py", line 48, in __init__
    self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
pywintypes.error: (6, 'SetConsoleMode', 'The handle is invalid.')

Thanks in advance.

@cyberw
Copy link
Collaborator

cyberw commented Feb 16, 2022

@DennisKrone can you have a look?

@cyberw
Copy link
Collaborator

cyberw commented Dec 3, 2023

Fixed "again" in c3ec9dd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants