@@ -292,10 +292,7 @@ trait IOApp extends IOAppPlatform {
292
292
*/
293
293
protected def logNonDaemonThreadsEnabled : Boolean =
294
294
Option (System .getProperty(" cats.effect.logNonDaemonThreadsOnExit" ))
295
- .map(_.toLowerCase()) match {
296
- case Some (value) => value.equalsIgnoreCase(" true" )
297
- case None => true // default to enabled
298
- }
295
+ .forall(_.equalsIgnoreCase(" true" ))
299
296
300
297
/**
301
298
* Controls the interval used by the non-daemon thread detector. Defaults to `10.seconds`.
@@ -311,37 +308,6 @@ trait IOApp extends IOAppPlatform {
311
308
.flatMap(time => Either .catchOnly[NumberFormatException ](time.toLong.millis).toOption)
312
309
.getOrElse(10 .seconds)
313
310
314
- /**
315
- * Defines what to do when IOApp detects that `main` is being invoked on a `Thread` which
316
- * isn't the main process thread. This condition can happen when we are running inside of an
317
- * `sbt run` with `fork := false`
318
- */
319
- def warnOnNonMainThreadDetected : Boolean =
320
- Option (System .getProperty(" cats.effect.warnOnNonMainThreadDetected" ))
321
- .map(_.equalsIgnoreCase(" true" ))
322
- .getOrElse(true )
323
-
324
- private def onNonMainThreadDetected (): Unit = {
325
- if (warnOnNonMainThreadDetected)
326
- System
327
- .err
328
- .println(
329
- """ |[WARNING] IOApp `main` is running on a thread other than the main thread.
330
- |This may prevent correct resource cleanup after `main` completes.
331
- |This condition could be caused by executing `run` in an interactive sbt session with `fork := false`.
332
- |To ensure proper cleanup, either
333
- | - set `Compile / run / fork := true` in this project
334
- | - use `fgRun` instead of `run`
335
- | - use 'bgStop` to terminate `run`
336
- | - update sbt to a version after 1.10.5
337
- |
338
- |To silence this warning set the system property:
339
- |`-Dcats.effect.warnOnNonMainThreadDetected=false`.
340
- |""" .stripMargin
341
- )
342
- else ()
343
- }
344
-
345
311
/**
346
312
* The entry point for your application. Will be called by the runtime when the process is
347
313
* started. If the underlying runtime supports it, any arguments passed to the process will be
@@ -359,9 +325,7 @@ trait IOApp extends IOAppPlatform {
359
325
def run (args : List [String ]): IO [ExitCode ]
360
326
361
327
final def main (args : Array [String ]): Unit = {
362
- // checked in openjdk 8-17; this attempts to detect when we're running under artificial environments, like sbt
363
- val isForked = Thread .currentThread().getId() == 1
364
- if (! isForked) onNonMainThreadDetected()
328
+ checkRunningOnNonMainThread()
365
329
366
330
val installed = if (runtime == null ) {
367
331
import unsafe .IORuntime
0 commit comments