pyth
pyth copied to clipboard
Add debug code to output before code is run (online compiler)
while debugging code, it is useful to have the python code printed to the output before the program runs. If the program hangs, it's very hard to debug because the code is never shown.
I'll guess you mean the Online Compiler, since offline compiler already does this. Not sure, if this is easy to implement.
Maybe the online compiler could simple terminate after running for 5 seconds and return the result, as far as it is computed. This would also prevent the server from crashing.
Yes, this is only an issue for people using the pyth online compiler for example on their phones
There is a very easy linux-only way to do the timeout using the signal module in the standard library. I don't think threads can be avoided if it has to be multiplataform.
One way to implement this without threads is with a command line flag to set the timeout, that would be enabled in the online versions.
When testing programs that seem to hang one can now (since 99838ee14d2b64692edac60c5952bcfabcffc0e0) add .q
to the start of the program. I would like to see a timeout function, though.
A fix for this, that covers much more, is to use web sockets to do real time communication from the server to the client. However, this is very involved.